Skip to content

Commit 35e8106

Browse files
authored
Fix Array.__array__ for numpy 2.1 (#2106)
* Fix Array.__array__ for numpy 2.1 * Add changelog * Depend on np.array for array coercions
1 parent c5c4698 commit 35e8106

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

docs/release.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,23 @@ Release notes
2424
2.18.3
2525
------
2626

27+
Enhancements
28+
~~~~~~~~~~~~
29+
* Added support for creating a copy of data when converting a `zarr.Array`
30+
to a numpy array.
31+
By :user:`David Stansby <dstansby>`
32+
2733
Maintenance
2834
~~~~~~~~~~~
2935
* Removed support for Python 3.9.
3036
By :user:`David Stansby <dstansby>`
31-
37+
3238
* Fix a regression when using orthogonal indexing with a scalar.
3339
By :user:`Deepak Cherian <dcherian>` :issue:`1931`
3440

41+
* Added compatibility with numpy 2.1.
42+
By :user:`David Stansby <dstansby>`
43+
3544

3645
.. _release_2.18.2:
3746

zarr/core.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,8 @@ def __eq__(self, other):
575575
# store comparison
576576
)
577577

578-
def __array__(self, *args):
579-
a = self[...]
580-
if args:
581-
a = a.astype(args[0])
582-
return a
578+
def __array__(self, dtype=None, copy=None):
579+
return np.array(self[...], dtype=dtype, copy=copy)
583580

584581
def islice(self, start=None, end=None):
585582
"""

0 commit comments

Comments
 (0)