Skip to content

Commit fbe2265

Browse files
committed
fix group overwrite -> mode conversion, and add locally-passing-but-globally-failing tests
1 parent 9b6f12d commit fbe2265

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ async def group(
677677
if overwrite:
678678
mode = "w"
679679
else:
680-
mode = "a"
680+
mode = "w-"
681681
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
682682

683683
if chunk_store is not None:

tests/test_api/test_asynchronous.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,15 @@ async def test_open_group_new_path(tmp_path: Path) -> None:
116116
# tmp_path exists, but tmp_path / "test.zarr" will not, which is important for this test
117117
store = tmp_path / "test.zarr"
118118
await group(store=store)
119+
120+
121+
async def test_open_group_old_path(tmp_path: Path) -> None:
122+
"""
123+
Test that zarr.api.asynchronous.group will not overwrite an existing file.
124+
125+
See https://github.com/zarr-developers/zarr-python/issues/3406
126+
"""
127+
store = tmp_path
128+
await group(store=store, overwrite=True, attributes={"existing_group": True})
129+
with pytest.raises(FileExistsError):
130+
await group(store=store)

0 commit comments

Comments
 (0)