Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/3431.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Creating a new group with `zarr.group` no longer errors.
This fixes a regression introduced in version 3.1.2.
42 changes: 14 additions & 28 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 18 additions & 1 deletion tests/test_api/test_asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Loading