From 2f47277973255e69920582636f3e3f7416b0aeb3 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 3 Sep 2025 19:32:28 +0100 Subject: [PATCH 1/4] Fix creating groups with group() --- src/zarr/api/asynchronous.py | 42 ++++++++++------------------- tests/test_api/test_asynchronous.py | 19 ++++++++++++- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index f206d48377..409601e474 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -670,38 +670,24 @@ async def group( g : group The new group. """ - - zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format) - mode: AccessModeLiteral if overwrite: mode = "w" else: - mode = "r+" - store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) - - if chunk_store is not None: - warnings.warn("chunk_store is not yet implemented", ZarrRuntimeWarning, stacklevel=2) - if cache_attrs is not None: - warnings.warn("cache_attrs is not yet implemented", ZarrRuntimeWarning, stacklevel=2) - if synchronizer is not None: - warnings.warn("synchronizer is not yet implemented", ZarrRuntimeWarning, stacklevel=2) - if meta_array is not None: - warnings.warn("meta_array is not yet implemented", ZarrRuntimeWarning, stacklevel=2) - - if attributes is None: - attributes = {} - - try: - return await AsyncGroup.open(store=store_path, zarr_format=zarr_format) - except (KeyError, FileNotFoundError): - _zarr_format = zarr_format or _default_zarr_format() - return await AsyncGroup.from_store( - store=store_path, - zarr_format=_zarr_format, - overwrite=overwrite, - attributes=attributes, - ) + mode = "a" + return await open_group( + store=store, + mode=mode, + chunk_store=chunk_store, + cache_attrs=cache_attrs, + synchronizer=synchronizer, + path=path, + zarr_version=zarr_version, + zarr_format=zarr_format, + meta_array=meta_array, + attributes=attributes, + storage_options=storage_options, + ) async def create_group( diff --git a/tests/test_api/test_asynchronous.py b/tests/test_api/test_asynchronous.py index 910fd2883c..a756b90c8a 100644 --- a/tests/test_api/test_asynchronous.py +++ b/tests/test_api/test_asynchronous.py @@ -2,14 +2,16 @@ import json from dataclasses import dataclass +from pathlib import Path from typing import TYPE_CHECKING import numpy as np import pytest from zarr import create_array -from zarr.api.asynchronous import _get_shape_chunks, _like_args, open +from zarr.api.asynchronous import _get_shape_chunks, _like_args, group, open from zarr.core.buffer.core import default_buffer_prototype +from zarr.core.group import AsyncGroup if TYPE_CHECKING: from typing import Any @@ -103,3 +105,18 @@ async def test_open_no_array() -> None: TypeError, match=r"open_group\(\) got an unexpected keyword argument 'shape'" ): await open(store=store, shape=(1,)) + + +async def test_open_group_new_path(tmp_path: Path) -> None: + """ + Test that zarr.api.asynchronous.group properly handles a string representation of a local file + path that does not yet exist. + See https://github.com/zarr-developers/zarr-python/issues/3406 + """ + # tmp_path exists, but tmp_path / "test.zarr" will not, which is important for this test + path = tmp_path / "test.zarr" + grp = await group(store=path, attributes={"a": 1}) + assert isinstance(grp, AsyncGroup) + # Calling group on an existing store should just open that store + grp = await group(store=path) + assert grp.attrs == {"a": 1} From 0637820ddef8a0b7d3c3908f5fc2cf51a9ebb5a7 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 3 Sep 2025 19:35:08 +0100 Subject: [PATCH 2/4] Add bugfix entry --- changes/3431.bufix.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/3431.bufix.rst diff --git a/changes/3431.bufix.rst b/changes/3431.bufix.rst new file mode 100644 index 0000000000..cdf166ddd5 --- /dev/null +++ b/changes/3431.bufix.rst @@ -0,0 +1,2 @@ +Creating a new group with `zarr.group` no longer errors. +This fixes a regression introduced in version 3.1.2. From 546c29137f29bb9390bd79e1c39c4989ca07e89d Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 3 Sep 2025 19:35:32 +0100 Subject: [PATCH 3/4] Fix import order --- tests/test_api/test_asynchronous.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_api/test_asynchronous.py b/tests/test_api/test_asynchronous.py index a756b90c8a..0f219fd727 100644 --- a/tests/test_api/test_asynchronous.py +++ b/tests/test_api/test_asynchronous.py @@ -2,7 +2,6 @@ import json from dataclasses import dataclass -from pathlib import Path from typing import TYPE_CHECKING import numpy as np @@ -14,6 +13,7 @@ from zarr.core.group import AsyncGroup if TYPE_CHECKING: + from pathlib import Path from typing import Any import numpy.typing as npt From fbce3696b941118581f80af1fa3f94c996fb2ca0 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 3 Sep 2025 19:41:03 +0100 Subject: [PATCH 4/4] Rename 3431.bufix.rst to 3431.bugfix.rst --- changes/{3431.bufix.rst => 3431.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changes/{3431.bufix.rst => 3431.bugfix.rst} (100%) diff --git a/changes/3431.bufix.rst b/changes/3431.bugfix.rst similarity index 100% rename from changes/3431.bufix.rst rename to changes/3431.bugfix.rst