Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiate iterators #182

Merged
merged 11 commits into from
Aug 14, 2024
Merged

Instantiate iterators #182

merged 11 commits into from
Aug 14, 2024

Conversation

ppinchuk
Copy link
Collaborator

A lot of the rex Resource classes were trying to be their own iterator instances, which can easily cause infinite loops. For example:

import os
from rex import TESTDATADIR, Resource

fp = os.path.join(TESTDATADIR, 'nsrdb/ri_100_nsrdb_2012.h5')  # or your fav file here - any works
with Resource(fp) as res:
    dataset_permutation = [(a, b) for a in res for b in res]

or for a more verbose option:

with Resource(fp) as res:
    for a in res:
        for b in res:
            print(f"{a}: {b}")

This PR forces the iterable Resource classes to instead create a unique iterator for every __iter__ invocation, thereby removing the infinite loop issue.

@ppinchuk ppinchuk added the bug Something isn't working label Aug 14, 2024
@ppinchuk ppinchuk self-assigned this Aug 14, 2024
Copy link
Collaborator

@bnb32 bnb32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautifully simple solution. Seems like this would have been a pain to track down.

@bnb32
Copy link
Collaborator

bnb32 commented Aug 14, 2024

btw does this close #181? If so you could remove the set / intersect logic from attrs

@ppinchuk
Copy link
Collaborator Author

btw does this close #181? If so you could remove the set / intersect logic from attrs

I don't think so - I didn't actually mess with the dataset name compilation logic

@ppinchuk ppinchuk merged commit dbcf643 into main Aug 14, 2024
16 checks passed
@ppinchuk ppinchuk deleted the pp/instance_iterators branch August 14, 2024 18:39
github-actions bot pushed a commit that referenced this pull request Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants