Skip to content

Commit 2a78497

Browse files
Added Attributes.asdict (#2221)
1 parent cd7321b commit 2a78497

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/zarr/core/attributes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ def put(self, d: dict[str, JSON]) -> None:
5151
{'a': 3, 'c': 4}
5252
"""
5353
self._obj = self._obj.update_attributes(d)
54+
55+
def asdict(self) -> dict[str, JSON]:
56+
return dict(self._obj.metadata.attributes)

tests/v3/test_attributes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ def test_put() -> None:
1111
attrs.put({"a": 3, "c": 4})
1212
expected = {"a": 3, "c": 4}
1313
assert dict(attrs) == expected
14+
15+
16+
def test_asdict() -> None:
17+
store = zarr.store.MemoryStore({}, mode="w")
18+
attrs = zarr.core.attributes.Attributes(
19+
zarr.Group.from_store(store, attributes={"a": 1, "b": 2})
20+
)
21+
result = attrs.asdict()
22+
assert result == {"a": 1, "b": 2}

0 commit comments

Comments
 (0)