Repository navigation
fix: move the advanced-index axis to the front like NumPy when advanced indices are separated - #984
Merged
hameerabbasi merged 1 commit intoOct 9, 2026
Conversation
…ed indices are separated
Contributor
Author
|
codecov/project fails on every PR (target 100%; codecov/patch passes here), and the benchmarks job fails on main too ( |
4 of 10 tasks
rmz-oz
approved these changes
Oct 8, 2026
rmz-oz
left a comment
There was a problem hiding this comment.
LGTM. I compared COO against numpy on 1203 keys of up to 3 entries built from ints, negative ints, np.int64, lists, int and bool arrays, step and reversed slices, None and Ellipsis on a 3d array: 30 mismatches on main, 0 here, and test_coo.py passes. fwiw a bool scalar key like s[True, :, [0, 2]] still comes out silently wrong ((2, 4) vs numpy's (2, 3, 5)), but it was already off on 0.19.2, so probably a separate issue.
hameerabbasi
approved these changes
Oct 9, 2026
4 of 10 tasks
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.
What type of PR is this? (check all applicable)
Related issues
Checklist
Please explain your changes below.
When the advanced indices in a key (arrays, and integers used together with them) are not next to each other, NumPy puts the axis they produce first. COO keeps it where the first array was, so the result has the wrong shape:
A small
advanced_index_axis()helper in_slicing.pyfinds these keys. It checks adjacency on the index as given, since anEllipsisseparates advanced indices in NumPy even when it expands to no axes, and returns wheregetitemput the advanced axis.COO.__getitem__then moves that axis to the front with a transpose. Keys whose advanced indices are adjacent (the common case) are unchanged.Tests: added the cases above (and a boolean-mask variant) to
test_advanced_indexing. A comparison with NumPy over ~28,000 keys built fromNone, integers, slices, two lists andEllipsison 2-d, 3-d and 4-d arrays had 4679 mismatches on main and none here. GCXS has the same behavior; I left it for a follow-up because #983 changes the same part of the GCXS indexing code.test_coo.py,test_compressed.py,test_array_function.pyandtest_dask_interop.pypass (4710 passed), and pre-commit (ruff check/format) is clean.