-
-
Notifications
You must be signed in to change notification settings - Fork 308
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
Feature/recursive members #2118
Feature/recursive members #2118
Conversation
Ensures that nested children are listed properly.
This PR adds a recursive=True flag to Group.members, for recursively listing the members of some hierarhcy. This is useful for Consolidated Metadata, which needs to recursively inspect children. IMO, it's useful (and simple) enough to include in the public API.
I'm pretty stumped by the failure at https://github.com/zarr-developers/zarr-python/actions/runs/10549846136/job/29225363145?pr=2118#step:6:374 The issue comes from a np.array([np.complex128(0.0, np.nan)]) == np.complex128(0) The actual array constructed by hypothesis is a bit different though. It's more like: In [23]: np.ndarray((1,), np.dtype("complex128"), b"\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x7f\xbaUFJ\xf0\x7f")[0]
Out[23]: np.complex128(nanj) The dtype and repr appear to be the same, but apparently they're different internally. Not sure how yet. Finally, something in the test runner appears to elevate the # inside the test run
array([False])
(Pdb) np.array([np.complex128(0.0, np.nan)]) == np.complex128(0)
array([False])
(Pdb) np.ndarray((1,), np.dtype("complex128"), b"\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x7f\xbaUFJ\xf0\x7f") == np.complex128(0)
*** RuntimeWarning: invalid value encountered in equal |
I'm partly giving up on that second hypothesis failure. It's possible that there's still a bug in zarr-python/src/zarr/core/buffer.py Lines 429 to 430 in 681f286
NaN like other values. But for this PR, we're able to work around it by filtering out that RuntimeWarning.
This should be ready for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes a breaking change to Group.members and Group.nmembers. Previously, these were properties, while AsyncGroup.members / nmembers were functions. I've changed the sync versions to align with the async versions (which is needed to support this keyword).
Agreed that this is useful enough to justify this change.
# See https://github.com/zarr-developers/zarr-python/pull/2118#issuecomment-2310280899 | ||
# Uncomment the next line to reproduce the original failure. | ||
# @reproduce_failure('6.111.2', b'AXicY2FgZGRAB/8/eLmF7qr/C5EDADZUBRM=') | ||
@pytest.mark.filterwarnings("ignore::RuntimeWarning") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcherian - would you mind looking into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a minefield 😬 The deepest I got was hypothesis.extra.numpy:ArrayStrategy.set_element
. Something about the sequence of operations and the data passed into the ndarray made it "weird", such that array == np.complex128(0.0)
raised an InvalidComparision warning. I'm not sure how to interpret the bytes at #2118 (comment).
this looks good to me! my one question is whether there would be any utility in using an integer to limit the recursion depth to a desired number of hierarchy levels, while preserving the option to traverse the entire group. e.g., the value of |
I was wondering about a limit-style argument too. I'll go ahead and implement that. |
I opted to implement this as a |
thanks @TomAugspurger! what's the reasoning for specifying the same behavior with two distinct values -- |
Purely for user convenience. Neither If I had to choose, I'd say |
I like this too! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good, pre-commit is red but I don't think that failure is related to content in the PR. If you're all done here @TomAugspurger then I am happy to merge
Yeah, this should be all set. The pre-commit errors are at #2131, I think from a new version of NumPy. I'll look into them today. |
(This currently depends on #2117. I'll rebase once that's merged to v3)
This PR adds a recursive=True flag to Group.members, for recursively
listing the members of some hierarchy. The default is unchanged (just list immediate children).
This includes a breaking change to Group.members and Group.nmembers. Previously, these were properties, while AsyncGroup.members / nmembers were functions. I've changed the sync versions to align with the async versions (which is needed to support this keyword).
This is useful for Consolidated Metadata, which needs to recursively
inspect children. IMO, it's useful (and simple) enough to include
in the public API.
Closes #2119
TODO: