Skip to content

Commit 26463d4

Browse files
authored
Merge branch 'main' into array-param
2 parents 5e56f56 + e738e2f commit 26463d4

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

changes/3431.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Creating a new group with `zarr.group` no longer errors.
2+
This fixes a regression introduced in version 3.1.2.

src/zarr/api/asynchronous.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -669,38 +669,24 @@ async def group(
669669
g : group
670670
The new group.
671671
"""
672-
673-
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
674-
675672
mode: AccessModeLiteral
676673
if overwrite:
677674
mode = "w"
678675
else:
679-
mode = "r+"
680-
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
681-
682-
if chunk_store is not None:
683-
warnings.warn("chunk_store is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
684-
if cache_attrs is not None:
685-
warnings.warn("cache_attrs is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
686-
if synchronizer is not None:
687-
warnings.warn("synchronizer is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
688-
if meta_array is not None:
689-
warnings.warn("meta_array is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
690-
691-
if attributes is None:
692-
attributes = {}
693-
694-
try:
695-
return await AsyncGroup.open(store=store_path, zarr_format=zarr_format)
696-
except (KeyError, FileNotFoundError):
697-
_zarr_format = zarr_format or _default_zarr_format()
698-
return await AsyncGroup.from_store(
699-
store=store_path,
700-
zarr_format=_zarr_format,
701-
overwrite=overwrite,
702-
attributes=attributes,
703-
)
676+
mode = "a"
677+
return await open_group(
678+
store=store,
679+
mode=mode,
680+
chunk_store=chunk_store,
681+
cache_attrs=cache_attrs,
682+
synchronizer=synchronizer,
683+
path=path,
684+
zarr_version=zarr_version,
685+
zarr_format=zarr_format,
686+
meta_array=meta_array,
687+
attributes=attributes,
688+
storage_options=storage_options,
689+
)
704690

705691

706692
async def create_group(

src/zarr/storage/_common.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131

3232

3333
def _dereference_path(root: str, path: str) -> str:
34-
assert isinstance(root, str)
35-
assert isinstance(path, str)
34+
if not isinstance(root, str):
35+
msg = f"{root=} is not a string ({type(root)=})" # type: ignore[unreachable]
36+
raise TypeError(msg)
37+
if not isinstance(path, str):
38+
msg = f"{path=} is not a string ({type(path)=})" # type: ignore[unreachable]
39+
raise TypeError(msg)
3640
root = root.rstrip("/")
3741
path = f"{root}/{path}" if root else path
3842
return path.rstrip("/")

tests/test_api/test_asynchronous.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import pytest
99

1010
from zarr import create_array
11-
from zarr.api.asynchronous import _get_shape_chunks, _like_args, open
11+
from zarr.api.asynchronous import _get_shape_chunks, _like_args, group, open
1212
from zarr.core.buffer.core import default_buffer_prototype
13+
from zarr.core.group import AsyncGroup
1314

1415
if TYPE_CHECKING:
16+
from pathlib import Path
1517
from typing import Any
1618

1719
import numpy.typing as npt
@@ -107,3 +109,18 @@ async def test_open_no_array() -> None:
107109
TypeError, match=r"open_group\(\) got an unexpected keyword argument 'shape'"
108110
):
109111
await open(store=store, shape=(1,))
112+
113+
114+
async def test_open_group_new_path(tmp_path: Path) -> None:
115+
"""
116+
Test that zarr.api.asynchronous.group properly handles a string representation of a local file
117+
path that does not yet exist.
118+
See https://github.com/zarr-developers/zarr-python/issues/3406
119+
"""
120+
# tmp_path exists, but tmp_path / "test.zarr" will not, which is important for this test
121+
path = tmp_path / "test.zarr"
122+
grp = await group(store=path, attributes={"a": 1})
123+
assert isinstance(grp, AsyncGroup)
124+
# Calling group on an existing store should just open that store
125+
grp = await group(store=path)
126+
assert grp.attrs == {"a": 1}

0 commit comments

Comments
 (0)