Repository navigation
fix(indexing): treat an empty list as an empty integer selection - #4518
Open
XXXXXQ-0206 wants to merge 3 commits into
Open
XXXXXQ-0206 wants to merge 3 commits into
XXXXXQ-0206 wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
XXXXXQ-0206
added a commit
to XXXXXQ-0206/zarr-python
that referenced
this pull request
Oct 16, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4518 +/- ##
=======================================
Coverage 94.71% 94.71%
=======================================
Files 94 94
Lines 13663 13663
=======================================
Hits 12941 12941
Misses 722 722
🚀 New features to boost your workflow:
|
XXXXXQ-0206
force-pushed
the
fix/empty-list-selection
branch
from
October 17, 2026 09:27
202518f to
d018fdd
Compare
d-v-b
requested changes
Oct 17, 2026
|
|
||
|
|
||
| def replace_lists(selection: SelectionNormalized) -> SelectionNormalized: | ||
| def _as_array(dim_sel: list[Any]) -> Any: |
Contributor
There was a problem hiding this comment.
don't nest function definitions without a reason
| @@ -510,9 +510,16 @@ def replace_ellipsis(selection: Any, shape: tuple[int, ...]) -> SelectionNormali | |||
|
|
|||
|
|
|||
| def replace_lists(selection: SelectionNormalized) -> SelectionNormalized: | |||
Contributor
There was a problem hiding this comment.
consider this instead:
def replace_lists(selection: SelectionNormalized) -> SelectionNormalized:
# An empty list has no dtype to infer; NumPy indexes with it as an empty integer array.
return tuple(
cast("ArrayOfIntOrBool", np.asarray(dim_sel, dtype=np.intp if len(dim_sel) == 0 else None))
if isinstance(dim_sel, list)
else dim_sel
for dim_sel in selection
)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
arr[[]]raisesIndexError: unsupported selection item for basic indexing. The same selection works as an empty integer array, and NumPy accepts it:IntSequence(declared atsrc/zarr/core/indexing.py:42) includeslist[int], so an empty list is a valid selection. The empty array form already returns(0, 4); only the list form is rejected.Cause:
is_integer_list(:233) andis_bool_list(:238) both requirelen(x) > 0, so an empty list falls through toBasicIndexer, which accepts only int and slice.The change drops
len(x) > 0fromis_integer_listonly, and makesreplace_listsusenp.intpfor an empty list (it otherwise infers float64).is_bool_listkeeps its guard, so an empty list stays an empty integer selection rather than an empty mask, as in NumPy.The new test covers empty lists in bare, tuple,
oindexandvindexforms, plus the empty-array, boolean-list and write controls. It fails on the base revision (src blob8ea59eb9->2926551a);tests/test_indexing.pygoes from 592 to 594 passed.ruff check/ruff format --checkare clean.If you would rather keep an empty list raising, we are happy to adjust.
For reviewers
The boolean-list guard is deliberately unchanged — please check that leaving
is_bool_listuntouched is how you want[]disambiguated.Author attestation
TODO
docs/user-guide/*.mdchanges/