Skip to content

fix: Scalar indexing returns numpy scalar, not 0-d array (fixes #3741)#3804

Closed
abishop1990 wants to merge 1 commit intozarr-developers:mainfrom
abishop1990:issue-3741-scalar-indexing
Closed

fix: Scalar indexing returns numpy scalar, not 0-d array (fixes #3741)#3804
abishop1990 wants to merge 1 commit intozarr-developers:mainfrom
abishop1990:issue-3741-scalar-indexing

Conversation

@abishop1990
Copy link
Contributor

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.

…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
@abishop1990
Copy link
Contributor Author

Superseded by PR #3805 with corrected test file location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array.__getitem__ returns 0-d ndarray for scalar indexing on dimensioned arrays

1 participant