From 35e8106278e94edd91dad370bab33f5633167044 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 23 Aug 2024 12:02:29 +0100 Subject: [PATCH] Fix Array.__array__ for numpy 2.1 (#2106) * Fix Array.__array__ for numpy 2.1 * Add changelog * Depend on np.array for array coercions --- docs/release.rst | 11 ++++++++++- zarr/core.py | 7 ++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/release.rst b/docs/release.rst index 9c2840a70a..697dfde3b8 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -24,14 +24,23 @@ Release notes 2.18.3 ------ +Enhancements +~~~~~~~~~~~~ +* Added support for creating a copy of data when converting a `zarr.Array` + to a numpy array. + By :user:`David Stansby ` + Maintenance ~~~~~~~~~~~ * Removed support for Python 3.9. By :user:`David Stansby ` - + * Fix a regression when using orthogonal indexing with a scalar. By :user:`Deepak Cherian ` :issue:`1931` +* Added compatibility with numpy 2.1. + By :user:`David Stansby ` + .. _release_2.18.2: diff --git a/zarr/core.py b/zarr/core.py index 141190a0c8..08234e193c 100644 --- a/zarr/core.py +++ b/zarr/core.py @@ -575,11 +575,8 @@ def __eq__(self, other): # store comparison ) - def __array__(self, *args): - a = self[...] - if args: - a = a.astype(args[0]) - return a + def __array__(self, dtype=None, copy=None): + return np.array(self[...], dtype=dtype, copy=copy) def islice(self, start=None, end=None): """