Skip to content

Commit d6610a0

Browse files
committed
Skip chunk coordinate enumeration in resize when array is only growing (zarr-developers#3650)
1 parent 229a690 commit d6610a0

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎src/zarr/core/array.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,12 @@ async def resize(self, new_shape: ShapeLike, delete_outside_chunks: bool = True)
18871887
assert len(new_shape) == len(self.metadata.shape)
18881888
new_metadata = self.metadata.update_shape(new_shape)
18891889

1890-
if delete_outside_chunks:
1890+
# ensure deletion is only run if array is shrinking as the delete_outside_chunks path is unbounded in memory
1891+
only_growing = all(
1892+
new >= old for new, old in zip(new_shape, self.metadata.shape, strict=True)
1893+
)
1894+
1895+
if delete_outside_chunks and not only_growing:
18911896
# Remove all chunks outside of the new shape
18921897
old_chunk_coords = set(self.metadata.chunk_grid.all_chunk_coords(self.metadata.shape))
18931898
new_chunk_coords = set(self.metadata.chunk_grid.all_chunk_coords(new_shape))

0 commit comments

Comments
 (0)