Skip to content

Commit 62910bc

Browse files
dcheriand-v-b
andauthored
Optimize attribute setting (#1741)
* Optimize attribute setting * Add release note --------- Co-authored-by: Davis Bennett <[email protected]>
1 parent 0cfd2be commit 62910bc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Unreleased
2020

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

2427
* [v3] Reuse the download array metadata when creating an ``Array``.
2528
By :user:`Deepak Cherian <dcherian>`.

zarr/attrs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,20 @@ def _put_nosync(self, d):
151151
if self.cache:
152152
self._cached_asdict = d
153153
else:
154-
if self.key in self.store:
154+
try:
155+
meta_unparsed = self.store[self.key]
155156
# Cannot write the attributes directly to JSON, but have to
156157
# store it within the pre-existing attributes key of the v3
157158
# metadata.
158159

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

161-
meta = self.store._metadata_class.parse_metadata(self.store[self.key])
162+
meta = self.store._metadata_class.parse_metadata(meta_unparsed)
162163
if "attributes" in meta and "filters" in meta["attributes"]:
163164
# need to preserve any existing "filters" attribute
164165
d["attributes"]["filters"] = meta["attributes"]["filters"]
165166
meta["attributes"] = d["attributes"]
166-
else:
167+
except KeyError:
167168
meta = d
168169
self.store[self.key] = json_dumps(meta)
169170
if self.cache:

0 commit comments

Comments
 (0)