Repository navigation
fix: raise a clear TypeError for non-string group keys - #4658
Open
1915rising wants to merge 2 commits into
Open
1915rising wants to merge 2 commits into
1915rising wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4658 +/- ##
=======================================
Coverage 94.91% 94.91%
=======================================
Files 96 96
Lines 14070 14070
=======================================
+ Hits 13354 13355 +1
+ Misses 716 715 -1
🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3387.
Indexing a group with a non-string key used to die deep in the storage layer. On current main the reporter's example gives:
That message comes from
str.joininsideStorePath.__truediv__and tells the user nothing about what they did wrong (in zarr v2 the same code returned the member named"0"; in 3.1.1 it was a bareAssertionError, which #3392 improved at the old_dereference_pathsite, but that check was lost when the path code was refactored).This change makes
StorePath.__truediv__run the appended path through the existingnormalize_path— the same validationStorePath.__init__already applies — so an invalid key raises the codebase's standard, clear error at the point of misuse:One line changed in
src/zarr/storage/_common.py. String keys are unaffected (normalize_pathoutput for a string is what the constructor would apply to the joined result anyway), andpathlib.Path/bytesoperands now behave the same way they do when passed toStorePathdirectly.I chose a clear
TypeErrorover silently converting int keys to strings: group member names are strings, and accepting0for"0"would hide bugs in calling code. Happy to change direction if maintainers would rather restore the v2 conversion.For reviewers
The behaviour change to look at is only the error for non-string keys; the valid-key path is unchanged. Regression coverage is in
test_group_getitemandtest_asyncgroup_getitem, asserting the newTypeErrorforgroup[0].Tests: the issue's repro before/after as above;
tests/test_group.py,tests/test_store/test_core.py,tests/test_store/test_utils.pyandtests/test_api.py— 1662 passed, 226 skipped (optional-dependency skips), 0 failures after the change; the same targeted getitem tests passed before the change (18 passed) with the repro failing as shown.Disclosure: this change was prepared with AI coding assistance, in line with the project's AI-assisted contributions guidance; every line has been reviewed and the repro and test runs above were executed against this exact code.
TODO
changes/