Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions changes/3444.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Trying to open a group at a path were a array already exists now raises a helpful error.
8 changes: 8 additions & 0 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from zarr.errors import (
ContainsArrayError,
ContainsGroupError,
GroupNotFoundError,
MetadataValidationError,
ZarrDeprecationWarning,
ZarrUserWarning,
Expand Down Expand Up @@ -673,6 +674,13 @@ def from_dict(
store_path: StorePath,
data: dict[str, Any],
) -> AsyncGroup:
node_type = data.pop("node_type", None)
if node_type == "array":
msg = f"An array already exists in store {store_path.store} at path {store_path.path}."
raise ContainsArrayError(msg)
elif node_type not in ("group", None):
msg = f"Node type in metadata ({node_type}) is not 'group'"
raise GroupNotFoundError(msg)
return cls(
metadata=GroupMetadata.from_dict(data),
store_path=store_path,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,3 +2234,9 @@ def test_get_roots(roots: tuple[str, ...]):
}
data = root_nodes | child_nodes
assert set(_get_roots(data)) == set(roots)


def test_open_array_as_group():
z = zarr.create_array(shape=(40, 50), chunks=(10, 10), dtype="f8", store={})
with pytest.raises(ContainsArrayError):
zarr.open_group(z.store)
Loading