Skip to content

Commit 1257dbf

Browse files
committed
Skip chunk coordinate enumeration in resize when array is only growing (zarr-developers#3650)
1 parent 7d8105f commit 1257dbf

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
@@ -1840,7 +1840,12 @@ async def resize(self, new_shape: ShapeLike, delete_outside_chunks: bool = True)
18401840
assert len(new_shape) == len(self.metadata.shape)
18411841
new_metadata = self.metadata.update_shape(new_shape)
18421842

1843-
if delete_outside_chunks:
1843+
# ensure deletion is only run if array is shrinking as the delete_outside_chunks path is unbounded in memory
1844+
only_growing = all(
1845+
new >= old for new, old in zip(new_shape, self.metadata.shape, strict=True)
1846+
)
1847+
1848+
if delete_outside_chunks and not only_growing:
18441849
# Remove all chunks outside of the new shape
18451850
old_chunk_coords = set(self.metadata.chunk_grid.all_chunk_coords(self.metadata.shape))
18461851
new_chunk_coords = set(self.metadata.chunk_grid.all_chunk_coords(new_shape))

0 commit comments

Comments
 (0)