From 79412e39963abbf88cb3bbdb259533b038f0c1d8 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 22 Aug 2024 09:02:26 +0100 Subject: [PATCH 1/3] Fix Array.__array__ for numpy 2.1 --- zarr/core.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zarr/core.py b/zarr/core.py index 141190a0c8..984ebdb2ea 100644 --- a/zarr/core.py +++ b/zarr/core.py @@ -575,10 +575,13 @@ def __eq__(self, other): # store comparison ) - def __array__(self, *args): + def __array__(self, dtype=None, copy=None): a = self[...] - if args: - a = a.astype(args[0]) + if dtype is not None: + a = a.astype(dtype=dtype) + + if copy is not None and copy: + return a.copy() return a def islice(self, start=None, end=None): From 35d022c5d860861fe6e3e143856a41d6494b8a52 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 22 Aug 2024 09:12:51 +0100 Subject: [PATCH 2/3] Add changelog --- docs/release.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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: From c88a6c7c7f69c8f3eb56ac913167fffec67da5e8 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 22 Aug 2024 09:14:14 +0100 Subject: [PATCH 3/3] Depend on np.array for array coercions --- zarr/core.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/zarr/core.py b/zarr/core.py index 984ebdb2ea..08234e193c 100644 --- a/zarr/core.py +++ b/zarr/core.py @@ -576,13 +576,7 @@ def __eq__(self, other): ) def __array__(self, dtype=None, copy=None): - a = self[...] - if dtype is not None: - a = a.astype(dtype=dtype) - - if copy is not None and copy: - return a.copy() - return a + return np.array(self[...], dtype=dtype, copy=copy) def islice(self, start=None, end=None): """