From 272d05a7957af20f52a9c5bdaceca94b3d1d738f Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Sat, 4 Jan 2025 00:01:15 +1100 Subject: [PATCH 1/2] Add test for #2490 --- tests/test_api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_api.py b/tests/test_api.py index 80e8555e11..fcdbd131b1 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, From ed916447c18cc5bef132486217278d509b1e5385 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Sat, 4 Jan 2025 00:03:27 +1100 Subject: [PATCH 2/2] Add 'w' to list of valid modes in open to create a group --- src/zarr/api/asynchronous.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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