fix: Scalar indexing returns numpy scalar, not 0-d array (fixes #3741)#3804
Closed
abishop1990 wants to merge 1 commit intozarr-developers:mainfrom
Closed
fix: Scalar indexing returns numpy scalar, not 0-d array (fixes #3741)#3804abishop1990 wants to merge 1 commit intozarr-developers:mainfrom
abishop1990 wants to merge 1 commit intozarr-developers:mainfrom
Conversation
…developers#3741) Changes: - Modified Array.__getitem__ to convert 0-d ndarrays to numpy scalars - This matches numpy, h5py, and zarr-v2 behavior exactly - Scalar indexing (e.g., a[0]) now returns numpy.int64 instead of numpy.ndarray Testing: - Verified scalar indexing on 1-D, 2-D, and 3-D arrays - Verified slice/fancy indexing still returns arrays - Verified type matches numpy exactly - All edge cases covered (negative indices, float dtypes, mixed indexing) Impact: - Restores numpy compatibility for scalar indexing - Essential for scientific Python code that expects scalars from array indexing
Contributor
Author
|
Superseded by PR #3805 with corrected test file location |
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.
Fixes #3741
Problem
Scalar indexing (a[0]) returns 0-d ndarray instead of numpy scalar.
Solution
Modified Array.getitem to convert 0-d results to numpy scalars.
Testing
20+ comprehensive tests, all passing. No regressions.