BUG: sparse: Fix advanced indexing using both slice and array #21022
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.
Fixes #21016
Advanced indexing with both slice and array indices provides incorrect shapes for examples such as
csr_array(np.arange(15).reshape((5, 3)))[:, [1, 2]]
. This is due to a bug introduced in #20120 and caught via nightly builds.This PR provides a test showing the problem (it copies a test function from
test_base.py
and adapts it to 2d sparse arrays). A fix is also included. The fix involves adding a case for when only one dimension's index-value is an array while the index also contains a slice in a separate dimension. The result should now mimic numpy's indexing behavior for advanced fancy indexing using both slices and arrays).This unfortunate bug would have been easier to find (and the PR introducing it easier to review) if we converted the
test_base.py
module to directly and fully test sparray methods as well as spmatrix (as is developing in #20894 and #20895). In the meantime, this example shows the power of quick feedback based on nightly builds. And hopefully this PR allows the tests run on nightly builds to pass.