Skip to content

Commit

Permalink
Turn some enumeration + getitem into zip()
Browse files Browse the repository at this point in the history
+ add some assertion instead of casting to int.
  • Loading branch information
Carreau committed Dec 15, 2020
1 parent ab22ee1 commit d8464d4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions zarr/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,9 @@ def __init__(self, selection, arr_shape):

chunk_loc_slices = []
last_dim_slice = None if selection[-1].step > 1 else selection.pop()
for i, sl in enumerate(selection):
for arr_shape_i, sl in zip(selection, arr_shape)):
dim_chunk_loc_slices = []
for i, x in enumerate(slice_to_range(sl, arr_shape[i])):
for x in slice_to_range(sl, self.arr_shape_i):
dim_chunk_loc_slices.append(slice(x, x + 1, 1))
chunk_loc_slices.append(dim_chunk_loc_slices)
if last_dim_slice:
Expand All @@ -934,4 +934,6 @@ def __iter__(self):
start = 0
for i, sl in enumerate(chunk_selection):
start += sl.start * np.prod(self.arr_shape[i + 1 :])
yield int(start), int(nitems), chunk_selection
assert isinstance(start, int)
assert isinstance(nitems, int)
yield start, nitems, chunk_selection

0 comments on commit d8464d4

Please sign in to comment.