Skip to content

Commit 4562e86

Browse files
committed
working dict serialization for _ImplicitGroupMetadata
1 parent 64b54bf commit 4562e86

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/zarr/core/group.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,12 +3258,12 @@ def _persist_metadata(
32583258

32593259
class _ImplicitGroupMetadata(GroupMetadata):
32603260
"""
3261-
This class represents the metadata document of a group that should created at some
3261+
This class represents the metadata document of a group that should be created at a
32623262
location in storage if and only if there is not already a group at that location.
32633263
32643264
This class is used to fill group-shaped "holes" in a dict specification of a Zarr hierarchy.
32653265
3266-
When attempting to write this class to disk, the writer should first check if a Zarr group
3266+
When attempting to write this class to storage, the writer should first check if a Zarr group
32673267
already exists at the desired location. If such a group does exist, the writer should do nothing.
32683268
If not, the writer should write this metadata document to storage.
32693269
@@ -3283,6 +3283,9 @@ def __init__(
32833283

32843284
super().__init__(attributes, zarr_format, consolidated_metadata)
32853285

3286+
def to_dict(self) -> dict[str, JSON]:
3287+
return asdict(self)
3288+
32863289

32873290
async def _from_flat(
32883291
store: StoreLike,

tests/test_group.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ConsolidatedMetadata,
2626
GroupMetadata,
2727
_from_flat,
28+
_ImplicitGroupMetadata,
2829
create_hierarchy,
2930
create_nodes,
3031
)
@@ -1609,6 +1610,28 @@ async def test_group_from_flat(store: Store, zarr_format, root_key: str):
16091610
assert members_observed_meta == members_expected_meta_relative
16101611

16111612

1613+
@pytest.mark.parametrize("store", ["memory"], indirect=True)
1614+
@pytest.mark.parametrize("zarr_format", [2, 3])
1615+
async def test_create_hierarchy_implicit_groups(store: Store, zarr_format):
1616+
"""
1617+
Test that writing a hierarchy with implicit groups does not result in altering an existing group
1618+
"""
1619+
spath = await make_store_path(store, path="")
1620+
key = "a"
1621+
attrs = {"name": key}
1622+
_ = await _from_flat(
1623+
store,
1624+
nodes={
1625+
key: GroupMetadata(zarr_format=zarr_format, attributes=attrs),
1626+
},
1627+
)
1628+
1629+
_ = await _collect_aiterator(
1630+
create_nodes(store_path=spath, nodes={key: _ImplicitGroupMetadata(zarr_format=zarr_format)})
1631+
)
1632+
assert zarr.open_group(store, path=key).metadata.attributes == attrs
1633+
1634+
16121635
@pytest.mark.parametrize("store", ["memory"], indirect=True)
16131636
def test_group_members_performance(store: Store) -> None:
16141637
"""

0 commit comments

Comments
 (0)