From e314f54f811173982f4acb720a3a072d9f11cbf9 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Fri, 20 Dec 2024 15:52:47 +0100 Subject: [PATCH 1/2] test and fix indexing for scalar arrays --- src/zarr/api/asynchronous.py | 2 +- tests/test_array.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 2d1c26e145..6559b2f4f8 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -574,7 +574,7 @@ async def array( z = await create(**kwargs) # fill with data - await z.setitem(slice(None), data) + await z.setitem(Ellipsis, data) return z diff --git a/tests/test_array.py b/tests/test_array.py index 263b536784..bd315e2241 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -782,3 +782,10 @@ async def test_special_complex_fill_values_roundtrip(fill_value: Any, expected: assert content is not None actual = json.loads(content.to_bytes()) assert actual["fill_value"] == expected + + +async def test_scalar_array(): + arr = zarr.array(1.5) + assert arr[...] == 1.5 + assert arr[()] == 1.5 + assert arr.shape == () From 21329580914a89db6f7f9fe9f161ee8c2246b395 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sun, 22 Dec 2024 13:52:57 +0100 Subject: [PATCH 2/2] fix mypy --- tests/test_array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_array.py b/tests/test_array.py index 2878310716..891538bc43 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -883,7 +883,7 @@ async def test_nbytes( assert arr.nbytes == np.prod(arr.shape) * arr.dtype.itemsize -async def test_scalar_array(): +async def test_scalar_array() -> None: arr = zarr.array(1.5) assert arr[...] == 1.5 assert arr[()] == 1.5