Skip to content

Commit 9cdfe49

Browse files
committed
better handling of chunk deletion after resize
1 parent 272a492 commit 9cdfe49

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

zarr/core.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,8 @@ def nbytes_stored(self):
309309

310310
@property
311311
def _cdata_shape(self):
312-
return tuple(
313-
int(np.ceil(s / c)) for s, c in zip(self._shape, self._chunks)
314-
)
312+
return tuple(int(np.ceil(s / c))
313+
for s, c in zip(self._shape, self._chunks))
315314

316315
@property
317316
def cdata_shape(self):
@@ -917,6 +916,7 @@ def _resize_nosync(self, *args):
917916
# normalize new shape argument
918917
old_shape = self._shape
919918
new_shape = normalize_resize_args(old_shape, *args)
919+
old_cdata_shape = self._cdata_shape
920920

921921
# update metadata
922922
self._shape = new_shape
@@ -928,17 +928,16 @@ def _resize_nosync(self, *args):
928928
for s, c in zip(new_shape, chunks))
929929

930930
# remove any chunks not within range
931-
for key in listdir(self._chunk_store, self._path):
932-
if key not in [array_meta_key, attrs_key]:
931+
for cidx in itertools.product(*[range(n) for n in old_cdata_shape]):
932+
if all(i < c for i, c in zip(cidx, new_cdata_shape)):
933+
pass # keep the chunk
934+
else:
935+
key = self._chunk_key(cidx)
933936
try:
934-
cidx = list(map(int, key.split('.')))
935-
except ValueError as e:
936-
raise RuntimeError('unexpected key: %r' % key)
937-
else:
938-
if all(i < c for i, c in zip(cidx, new_cdata_shape)):
939-
pass # keep the chunk
940-
else:
941-
del self._chunk_store[self._key_prefix + key]
937+
del self._chunk_store[key]
938+
except KeyError:
939+
# chunk not initialized
940+
pass
942941

943942
def append(self, data, axis=0):
944943
"""Append `data` to `axis`.

0 commit comments

Comments
 (0)