Skip to content

Commit

Permalink
Optimize attribute setting (#1741)
Browse files Browse the repository at this point in the history
* Optimize attribute setting

* Add release note

---------

Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
  • Loading branch information
dcherian and d-v-b committed Apr 5, 2024
1 parent 0cfd2be commit 62910bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Unreleased

Enhancements
~~~~~~~~~~~~
* [v3] Dramatically reduce number of ``__contains_`` requests in favor of optimistically calling `__getitem__`
and handling any error that may arise.
By :user:`Deepak Cherian <dcherian>`.

* [v3] Reuse the download array metadata when creating an ``Array``.
By :user:`Deepak Cherian <dcherian>`.
Expand Down
7 changes: 4 additions & 3 deletions zarr/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,20 @@ def _put_nosync(self, d):
if self.cache:
self._cached_asdict = d
else:
if self.key in self.store:
try:
meta_unparsed = self.store[self.key]
# Cannot write the attributes directly to JSON, but have to
# store it within the pre-existing attributes key of the v3
# metadata.

# Note: this changes the store.counter result in test_caching_on!

meta = self.store._metadata_class.parse_metadata(self.store[self.key])
meta = self.store._metadata_class.parse_metadata(meta_unparsed)
if "attributes" in meta and "filters" in meta["attributes"]:
# need to preserve any existing "filters" attribute
d["attributes"]["filters"] = meta["attributes"]["filters"]
meta["attributes"] = d["attributes"]
else:
except KeyError:
meta = d
self.store[self.key] = json_dumps(meta)
if self.cache:
Expand Down

0 comments on commit 62910bc

Please sign in to comment.