Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default zarr.open to open_group if shape is not provided #2158

Open
wants to merge 9 commits into
base: v3
Choose a base branch
from
5 changes: 5 additions & 0 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ async def open(
if path is not None:
store_path = store_path / path

if "shape" not in kwargs and mode in {"a", "w", "w-"}:
try:
return await open_group(store=store_path, zarr_format=zarr_format, mode=mode, **kwargs)
except AssertionError:
agoodm marked this conversation as resolved.
Show resolved Hide resolved
return await open_array(store=store_path, zarr_format=zarr_format, mode=mode, **kwargs)
agoodm marked this conversation as resolved.
Show resolved Hide resolved
try:
return await open_array(store=store_path, zarr_format=zarr_format, mode=mode, **kwargs)
except KeyError:
Expand Down
7 changes: 6 additions & 1 deletion tests/v3/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ def test_open_with_mode_r_plus(tmp_path: pathlib.Path) -> None:
z2[:] = 3


def test_open_with_mode_a(tmp_path: pathlib.Path) -> None:
async def test_open_with_mode_a(tmp_path: pathlib.Path) -> None:
# Open without shape argument should default to group
g = zarr.open(store=tmp_path, mode="a")
assert isinstance(g, Group)
await g.store_path.delete()
agoodm marked this conversation as resolved.
Show resolved Hide resolved

# 'a' means read/write (create if doesn't exist)
arr = zarr.open(store=tmp_path, mode="a", shape=(3, 3))
assert isinstance(arr, Array)
agoodm marked this conversation as resolved.
Show resolved Hide resolved
Expand Down