Skip to content

Commit a34c1f4

Browse files
committed
Optimize attribute setting
1 parent aa9a0d5 commit a34c1f4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

zarr/attrs.py

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

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

159-
meta = self.store._metadata_class.parse_metadata(self.store[self.key])
160+
meta = self.store._metadata_class.parse_metadata(meta_unparsed)
160161
if "attributes" in meta and "filters" in meta["attributes"]:
161162
# need to preserve any existing "filters" attribute
162163
d["attributes"]["filters"] = meta["attributes"]["filters"]
163164
meta["attributes"] = d["attributes"]
164-
else:
165+
except KeyError:
165166
meta = d
166167
self.store[self.key] = json_dumps(meta)
167168
if self.cache:

0 commit comments

Comments
 (0)