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

reader() is not idempotent #264

Open
joshua-gould opened this issue Mar 20, 2023 · 1 comment
Open

reader() is not idempotent #264

joshua-gould opened this issue Mar 20, 2023 · 1 comment

Comments

@joshua-gould
Copy link
Contributor

Here's a test that illustrates the unexpected behavior:

 def test_reader_twice(self):
        # calling reader() returns different results
        filename = str(self.path.join("labels"))
        reader = Reader(parse_url(filename))
        assert len(list(reader())) == len(list(reader()))
@will-moore
Copy link
Member

Thanks for the feedback.
This seems to be something in the handling of labels.

>>> from ome_zarr.io import parse_url
>>> from ome_zarr.reader import Reader
>>> url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr"
>>> reader = Reader(parse_url(url))
>>> list(reader())
[https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr/ [zgroup], https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr/labels/ [zgroup] (hidden), https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr/labels/0/ [zgroup] (hidden)]
>>> list(reader())
[https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr/ [zgroup]]

The root node keeps track of nodes is has seen as we traverse the graph, so as to prevent recursion.
The labels nodes are seen on the first call of reader() and this isn't reset for the 2nd call, so the labels nodes are not visited /returned on the 2nd call.

Maybe the API shouldn't allow this and we should just do:

nodes = read(parse_url(url))

or even just:

nodes = read(url)

cc @joshmoore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants