diff --git a/src/zarr/core/attributes.py b/src/zarr/core/attributes.py index 62ff5fc935..913a4b74ed 100644 --- a/src/zarr/core/attributes.py +++ b/src/zarr/core/attributes.py @@ -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) diff --git a/tests/v3/test_attributes.py b/tests/v3/test_attributes.py index 65b6a02e8d..14c60492be 100644 --- a/tests/v3/test_attributes.py +++ b/tests/v3/test_attributes.py @@ -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}