Skip to content

Commit 00e7814

Browse files
authored
Ensure absolute paths work with consolidate metadata (#3428)
* Ensure absolute paths work with consolidate metadata * bug fix note * ruff format
1 parent 6c04c82 commit 00e7814

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

changes/3428.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure syntax like ``root['/subgroup']`` works equivalently to ``root['subgroup']`` when using consolidated metadata.

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def _getitem_consolidated(
735735
assert self.metadata.consolidated_metadata is not None
736736

737737
# we support nested getitems like group/subgroup/array
738-
indexers = key.split("/")
738+
indexers = normalize_path(key).split("/")
739739
indexers.reverse()
740740
metadata: ArrayV2Metadata | ArrayV3Metadata | GroupMetadata = self.metadata
741741

tests/test_metadata/test_consolidated.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,21 @@ async def test_use_consolidated_for_children_members(
692692
expected = ["b", "b/c"]
693693
assert result == expected
694694

695+
async def test_absolute_path_for_subgroup(self, memory_store: zarr.storage.MemoryStore) -> None:
696+
root = await zarr.api.asynchronous.create_group(store=memory_store)
697+
await root.create_group("a/b")
698+
with pytest.warns(
699+
ZarrUserWarning,
700+
match="Consolidated metadata is currently not part in the Zarr format 3 specification.",
701+
):
702+
await zarr.api.asynchronous.consolidate_metadata(memory_store)
703+
704+
group = await zarr.api.asynchronous.open_group(store=memory_store)
705+
subgroup = await group.getitem("/a")
706+
assert isinstance(subgroup, AsyncGroup)
707+
members = [x async for x in subgroup.keys()] # noqa: SIM118
708+
assert members == ["b"]
709+
695710

696711
@pytest.mark.parametrize("fill_value", [np.nan, np.inf, -np.inf])
697712
async def test_consolidated_metadata_encodes_special_chars(

0 commit comments

Comments
 (0)