Skip to content

Update NDArrayLike typing for NumPy 2.0 compatibility (fixes #3780)#3809

Open
abishop1990 wants to merge 2 commits intozarr-developers:mainfrom
abishop1990:issue-3780-ndarray-like-typing
Open

Update NDArrayLike typing for NumPy 2.0 compatibility (fixes #3780)#3809
abishop1990 wants to merge 2 commits intozarr-developers:mainfrom
abishop1990:issue-3780-ndarray-like-typing

Conversation

@abishop1990
Copy link
Contributor

Summary

This PR updates the NDArrayLike Protocol to correctly represent NumPy 2.0+ typing for array transformations.

Changes

Methods that transform arrays now return NDArrayLike instead of Self:

  • reshape - changes shape
  • view - changes dtype
  • astype - changes dtype
  • copy - returns new instance
  • transpose - changes shape
  • ravel - flattens to 1D

This aligns with NumPy 2.0's stricter typing system that better represents shape and dtype transformations.

Testing

✅ All 5372 tests pass
✅ All lint checks pass
✅ No type checking errors

Fixes #3780

Test User and others added 2 commits March 21, 2026 12:02
Methods that transform arrays (reshape, view, astype, copy, transpose, ravel)
now correctly return NDArrayLike instead of Self to accurately represent shape
and dtype changes in NumPy 2.0+ typing.
@abishop1990
Copy link
Contributor Author

Failing error here seems to be on a bad gateway installing hatch, not sure it's an actual issue.

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.

NDArrayLike Typing with newer numpy typing

1 participant