diff --git a/changes/3428.bugfix.rst b/changes/3428.bugfix.rst new file mode 100644 index 0000000000..d15a3db3ba --- /dev/null +++ b/changes/3428.bugfix.rst @@ -0,0 +1 @@ +Ensure syntax like ``root['/subgroup']`` works equivalently to ``root['subgroup']`` when using consolidated metadata. diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 7b2e506a14..15a256fb5d 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -735,7 +735,7 @@ def _getitem_consolidated( assert self.metadata.consolidated_metadata is not None # we support nested getitems like group/subgroup/array - indexers = key.split("/") + indexers = normalize_path(key).split("/") indexers.reverse() metadata: ArrayV2Metadata | ArrayV3Metadata | GroupMetadata = self.metadata diff --git a/tests/test_metadata/test_consolidated.py b/tests/test_metadata/test_consolidated.py index 0995be3c6d..9e8b763ef7 100644 --- a/tests/test_metadata/test_consolidated.py +++ b/tests/test_metadata/test_consolidated.py @@ -692,6 +692,21 @@ async def test_use_consolidated_for_children_members( expected = ["b", "b/c"] assert result == expected + async def test_absolute_path_for_subgroup(self, memory_store: zarr.storage.MemoryStore) -> None: + root = await zarr.api.asynchronous.create_group(store=memory_store) + await root.create_group("a/b") + with pytest.warns( + ZarrUserWarning, + match="Consolidated metadata is currently not part in the Zarr format 3 specification.", + ): + await zarr.api.asynchronous.consolidate_metadata(memory_store) + + group = await zarr.api.asynchronous.open_group(store=memory_store) + subgroup = await group.getitem("/a") + assert isinstance(subgroup, AsyncGroup) + members = [x async for x in subgroup.keys()] # noqa: SIM118 + assert members == ["b"] + @pytest.mark.parametrize("fill_value", [np.nan, np.inf, -np.inf]) async def test_consolidated_metadata_encodes_special_chars(