Skip to content

Commit a53baa4

Browse files
committed
Omit chunks with no elements in slice selection with step
This stops chunks being read unnecessarily when a slice selection with a step was used. Previously all chunks spanning the start-end range would be used regardless of whether they contained any elements. Fixes zarr-developers#843.
1 parent 2dcffcd commit a53baa4

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎zarr/indexing.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ def __iter__(self):
216216
dim_chunk_sel = slice(dim_chunk_sel_start, dim_chunk_sel_stop, self.step)
217217
dim_chunk_nitems = ceildiv((dim_chunk_sel_stop - dim_chunk_sel_start),
218218
self.step)
219+
220+
# If there are no elements on the selection within this chunk, then skip
221+
if dim_chunk_nitems == 0:
222+
continue
223+
219224
dim_out_sel = slice(dim_out_offset, dim_out_offset + dim_chunk_nitems)
220225

221226
yield ChunkDimProjection(dim_chunk_ix, dim_chunk_sel, dim_out_sel)

0 commit comments

Comments
 (0)