Skip to content

Commit 62b198e

Browse files
committed
add test for creation under a parent array
1 parent bfba0e5 commit 62b198e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/zarr/core/metadata/io.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ async def save_metadata(
8787
try:
8888
await asyncio.gather(*ensure_array_awaitables)
8989
except ContainsArrayError as e:
90-
set_awaitables = [] # clear awaitables to avoid printed RuntimeWarning: coroutine was never awaited
90+
# clear awaitables to avoid RuntimeWarning: coroutine was never awaited
91+
for awaitable in set_awaitables:
92+
awaitable.close()
93+
9194
raise ValueError(
9295
f"A parent of {store_path} is an array - only groups may have child nodes."
9396
) from e

tests/test_group.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,24 @@ def test_group_create_array(
761761
assert np.array_equal(array[:], data)
762762

763763

764+
@pytest.mark.parametrize("method", ["create_array", "create_group"])
765+
def test_create_with_parent_array(store: Store, zarr_format: ZarrFormat, method: str):
766+
"""Test that groups/arrays cannot be created under a parent array."""
767+
768+
# create a group with a child array
769+
group = Group.from_store(store, zarr_format=zarr_format)
770+
group.create_array(name="arr_1", shape=(10, 10), dtype="uint8")
771+
772+
error_msg = r"A parent of .* is an array - only groups may have child nodes."
773+
if method == "create_array":
774+
with pytest.raises(ValueError, match=error_msg):
775+
group.create_array("arr_1/group_1/group_2/arr_2", shape=(10, 10), dtype="uint8")
776+
777+
else:
778+
with pytest.raises(ValueError, match=error_msg):
779+
group.create_group("arr_1/group_1/group_2/group_3")
780+
781+
764782
def test_group_array_creation(
765783
store: Store,
766784
zarr_format: ZarrFormat,

0 commit comments

Comments
 (0)