Skip to content

Optimize attribute setting #1741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2024
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 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>`.

* Optimize ``Array.info`` so that it calls `getsize` only once.
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 @@ -149,19 +149,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