diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 75c043fc1a..f54a824088 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -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"}: 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 diff --git a/tests/test_api.py b/tests/test_api.py index 2b48d3bcdc..6700f6b5e3 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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,