diff --git a/changes/3431.bugfix.rst b/changes/3431.bugfix.rst new file mode 100644 index 0000000000..cdf166ddd5 --- /dev/null +++ b/changes/3431.bugfix.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. 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..0f219fd727 100644 --- a/tests/test_api/test_asynchronous.py +++ b/tests/test_api/test_asynchronous.py @@ -8,10 +8,12 @@ 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 pathlib import Path from typing import Any import numpy.typing as npt @@ -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}