Repository navigation
fix: dispatch short boolean ndarray masks like NumPy - #4519
Open
XXXXXQ-0206 wants to merge 2 commits into
Open
XXXXXQ-0206 wants to merge 2 commits into
XXXXXQ-0206 wants to merge 2 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 17, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4519 +/- ##
=======================================
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/bool-array-mask-dispatch
branch
from
October 17, 2026 09:26
1b79da9 to
7a3ec17
Compare
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
A boolean
ndarrayused as a bare mask raises, while the equivalent list form and.oindexwork:An empty boolean array (
a[np.array([], dtype=bool)]) fails the same way, while NumPy returns(0, 4).Cause:
is_pure_fancy_indexing(src/zarr/core/indexing.py:283-285) returns True for any boolean ndarray, soArray.__getitem__(src/zarr/core/array.py:2750-2751) takes thevindexpath, andVIndex.__getitem__(indexing.py:1441-1462) only accepts coordinate arrays or a full-shape mask. The orthogonal path already handles short masks today (a.oindex[mask]gives(2, 4)), so this is a dispatch problem rather than a missing capability.The change is in two places: only full-shape masks take the vectorized path (
selection.ndim == ndim and selection.size > 0), andBoolArrayDimIndexeraccepts a zero-length mask. A non-empty mask whose length does not match the axis still raises, as NumPy does.For reviewers
Please confirm that keeping the length-mismatch error is the behaviour you want — it matches NumPy, and the new tests pin it as a negative case.
Testing
The new tests are parameterised over
zarr_format[2, 3]. They fail on the base revision (src blob8ea59eb9->17970b6a) and pass with the change. Full suite,pytest -q --ignore=tests/benchmarks: 12414 passed, 1225 skipped, 4 xfailed.ruff check/ruff format --checkare clean. Checked against NumPy 2.5.4 and 2.0.2 (the version pinned inmin_deps).Not covered here: 0-d boolean arrays and multi-dimensional partial masks (for example a 3-D array with a
(2, 3)mask) raise both before and after this change. That is not a regression, but it is a separate discussion.Author attestation
TODO
docs/user-guide/*.mdchanges/