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: 1 addition & 1 deletion src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async def open(
store_path = await make_store_path(store, mode=mode, path=path, storage_options=storage_options)

# TODO: the mode check below seems wrong!
if "shape" not in kwargs and mode in {"a", "r", "r+"}:
if "shape" not in kwargs and mode in {"a", "r", "r+", "w"}:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Based on the list of modes, I think the only thing missing here is "w-", so in the future we could also consider simply checking that mode is not "w-", but I don't think we need to do that here.

try:
metadata_dict = await get_array_metadata(store_path, zarr_format=zarr_format)
# TODO: remove this cast when we fix typing for array metadata dicts
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,13 @@ async def test_open_falls_back_to_open_group_async() -> None:
assert group.attrs == {"key": "value"}


def test_open_mode_write_creates_group(tmp_path: pathlib.Path) -> None:
# https://github.com/zarr-developers/zarr-python/issues/2490
zarr_dir = tmp_path / "test.zarr"
group = zarr.open(zarr_dir, mode="w")
assert isinstance(group, Group)


async def test_metadata_validation_error() -> None:
with pytest.raises(
MetadataValidationError,
Expand Down
Loading