Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0c8e7f7
WIP - backwards compat
TomAugspurger Aug 18, 2024
fa9e51d
fixup put
TomAugspurger Aug 19, 2024
8fdb605
rm consolidated
TomAugspurger Aug 19, 2024
0ac17cc
typing fixup
TomAugspurger Aug 19, 2024
be2b3cd
revert unneded change
TomAugspurger Aug 19, 2024
94933b3
fixup
TomAugspurger Aug 19, 2024
44ad6c7
deprecate positional args
TomAugspurger Aug 28, 2024
08e7f3c
attribute
TomAugspurger Aug 28, 2024
f937468
Fixup
TomAugspurger Aug 29, 2024
784cb28
Merge remote-tracking branch 'upstream/v3' into user/tom/fix/v2-compat
TomAugspurger Sep 3, 2024
b01e61c
Merge remote-tracking branch 'upstream/v3' into user/tom/fix/v2-compat
TomAugspurger Sep 6, 2024
c519fbe
fixup
TomAugspurger Sep 6, 2024
46c2c11
fixup
TomAugspurger Sep 6, 2024
1933f57
fixup
TomAugspurger Sep 6, 2024
36a2ceb
fixup
TomAugspurger Sep 6, 2024
1ae1cfd
fixup
TomAugspurger Sep 6, 2024
9f5429f
fixup
TomAugspurger Sep 6, 2024
a5ad0ca
fixup
TomAugspurger Sep 6, 2024
3d04845
Merge remote-tracking branch 'upstream/v3' into user/tom/fix/v2-compat
TomAugspurger Sep 16, 2024
b710c64
fixup
TomAugspurger Sep 16, 2024
0ab29d1
fixup
TomAugspurger Sep 16, 2024
aa1e3bc
fixup
TomAugspurger Sep 16, 2024
fb4bb85
fixup
TomAugspurger Sep 16, 2024
1cc84ab
fixup
TomAugspurger Sep 16, 2024
559399e
ci
TomAugspurger Sep 16, 2024
16bad38
Merge remote-tracking branch 'upstream/v3' into user/tom/fix/v2-compat
TomAugspurger Sep 19, 2024
f7f8457
Merge branch 'v3' into user/tom/fix/v2-compat
jhamman Sep 19, 2024
56431fe
Merge remote-tracking branch 'upstream/v3' into user/tom/fix/v2-compat
TomAugspurger Sep 19, 2024
b13dee3
fixup
TomAugspurger Sep 19, 2024
348aed8
Merge remote-tracking branch 'upstream/v3' into user/tom/fix/v2-compat
TomAugspurger Sep 20, 2024
2327141
fixup
TomAugspurger Sep 20, 2024
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
Prev Previous commit
Next Next commit
fixup put
  • Loading branch information
TomAugspurger committed Aug 29, 2024
commit fa9e51d747927e0baeb8c7d7b392b8cda32453c7
18 changes: 14 additions & 4 deletions src/zarr/core/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ def __len__(self) -> int:
return len(self._obj.metadata.attributes)

def put(self, d: Mapping[str, JSON]) -> None:
# Backwards compat for 2.x API.
new_attrs = dict(self._obj.metadata.attributes)
new_attrs.update(d)
self._obj = self._obj.update_attributes(new_attrs)
"""
Overwrite all attributes with the values from `d`.

Equivalent to the following pseudo-code, but performed atomically.

.. code-block:: python

>>> attrs = {"a": 1, "b": 2}
>>> attrs.clear()
>>> attrs.update({"a": 3", "c": 4})
>>> attrs
{'a': 3, 'c': 4}
"""
self._obj = self._obj.update_attributes(d)
13 changes: 13 additions & 0 deletions tests/v3/test_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import zarr.core
import zarr.core.attributes
import zarr.store


def test_put():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in principle we could test this functionality for other stores. but I also think testing the full product of [array / group features * stores] is excessive. I guess as long as we are confident that we are densely testing the core store APIs across store types, then it's fine to just test something derived from the store APIs on a single store.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in this case it's probably OK, since the test here is focused on the behavior of Attributes. This happens to require a reference to a Group (which requires a Store) but hopefully that interface is sufficiently covered by other tests.

store = zarr.store.MemoryStore({}, mode="w")
attrs = zarr.core.attributes.Attributes(
zarr.Group.from_store(store, attributes={"a": 1, "b": 2})
)
attrs.put({"a": 3, "c": 4})
expected = {"a": 3, "c": 4}
assert dict(attrs) == expected
4 changes: 3 additions & 1 deletion tests/v3/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def test_group_create(
Test that `Group.from_store` works as expected.
"""
attributes = {"foo": 100}
group = Group.from_store(store, attributes=attributes, zarr_format=zarr_format, exists_ok=exists_ok)
group = Group.from_store(
store, attributes=attributes, zarr_format=zarr_format, exists_ok=exists_ok
)

assert group.attrs == attributes

Expand Down