Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/zarr/core/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ def put(self, d: dict[str, JSON]) -> None:
{'a': 3, 'c': 4}
"""
self._obj = self._obj.update_attributes(d)

def asdict(self) -> dict[str, JSON]:
return dict(self._obj.metadata.attributes)
9 changes: 9 additions & 0 deletions tests/v3/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ def test_put() -> None:
attrs.put({"a": 3, "c": 4})
expected = {"a": 3, "c": 4}
assert dict(attrs) == expected


def test_asdict() -> None:
store = zarr.store.MemoryStore({}, mode="w")
attrs = zarr.core.attributes.Attributes(
zarr.Group.from_store(store, attributes={"a": 1, "b": 2})
)
result = attrs.asdict()
assert result == {"a": 1, "b": 2}