-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Ensure that chunks is tuple of ints upon array creation #1470
Conversation
(Launched workflows) |
Rebased over main |
zarr/util.py
Outdated
return wrapper | ||
|
||
|
||
@_as_int_tuple |
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.
normalize_shape
already does shape = tuple(int(s) for s in shape)
, so what is the purpose of decorating this function here?
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 is a safeguard for a future additions of early returns. I can remove the decorator here if desired.
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.
what about removing the decorator and adding a chunks = tuple(int(s) for s in chunks)
line to the end of normalize chunks?
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.
I had that as an option in commit 4693cb8 but there are 3 different return statements in normalize_chunks
.
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.
in that case I would recommend introducing a _chunks
variable in that function that gets returned at the end, and replacing the early returns with assignment to _chunks
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.
Note: None of the early returns in normalize_chunks
break my added tests
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.
Also, I am happy with any of these options:
- decorator on
normalize_chunks
andnormalize_shape
- decorator on
normalize_chunks
chunks = tuple(int(s) for s in chunks)
at the end ofnormalize_chunks
I'll pick whatever zarr maintainers think is most appropriate for the code base.
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.
I think I prefer option 3, because at the end of the day this is just about ensuring that functions return the correct type, and I don't think we need decorators for that.
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.
I reverted to option 3
After discussion in zarr-developers#1470, this was selected as the best option
Looks good! As an aside, it's weird that we accept booleans for specifying chunks, but I guess it's far too late to change that, unless we were planning a major version increment. |
Codecov Report
@@ Coverage Diff @@
## main #1470 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 37 37
Lines 14723 14732 +9
=========================================
+ Hits 14723 14732 +9
|
Thanks, guys! Happy to get this in. Also happy to hear if there is anything that should be done so that mypy could detect that a cast was needed. |
[Description of PR]
This PR will make sure that chunks of an array are created as
tuple[int, ..]
, even if provided astuple[float, ...]
(#1461). This is already the case for shape and this PR ensures that the behavior is the same between those two.I opened this as a draft PR with a failing test to ensure that github actions fail as expected. I will add the fix and push separately. Please feel free to squash as needed upon merge of the PR.
Fixes #1461
TODO: