From 5d4f44599e511b3eea93bcb6317c82bdf7354926 Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Fri, 26 Jun 2026 15:54:30 +0200 Subject: [PATCH] Fix scalar array save and load --- changes/3469.bugfix.md | 1 + src/zarr/api/asynchronous.py | 4 ++-- tests/test_api.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 changes/3469.bugfix.md diff --git a/changes/3469.bugfix.md b/changes/3469.bugfix.md new file mode 100644 index 0000000000..eb56e87476 --- /dev/null +++ b/changes/3469.bugfix.md @@ -0,0 +1 @@ +Fixed `save_array`, `Group.__setitem__`, and `load` for 0-dimensional arrays. diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 7f185535df..1908a1a11e 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -304,7 +304,7 @@ async def load( obj = await open(store=store, path=path, zarr_format=zarr_format) if isinstance(obj, AsyncArray): - return await obj.getitem(slice(None)) + return await obj.getitem(Ellipsis) else: raise NotImplementedError("loading groups not yet supported") @@ -482,7 +482,7 @@ async def save_array( overwrite=overwrite, **kwargs, ) - await new.setitem(slice(None), arr) + await new.setitem(Ellipsis, arr) async def save_group( diff --git a/tests/test_api.py b/tests/test_api.py index 503aeee405..1b4414ae63 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -396,6 +396,22 @@ def test_save(store: Store, n_args: int, n_kwargs: int, path: None | str) -> Non assert group.nmembers() == n_args + n_kwargs +@pytest.mark.parametrize( + "data", + [ + np.array(42, dtype=np.int64), + np.array("teststr", dtype=np.bytes_), + ], +) +@pytest.mark.filterwarnings("ignore::zarr.errors.UnstableSpecificationWarning") +def test_group_setitem_loads_scalar_arrays(sync_store: Store, data: np.ndarray) -> None: + root = zarr.open_group(store=sync_store) + root["test"] = data + + assert_array_equal(root["test"][...], data) + assert_array_equal(zarr.load(store=sync_store, path="test"), data) + + def test_save_errors() -> None: with pytest.raises(ValueError, match="at least one array must be provided"): # no arrays provided