Skip to content

Commit 3033817

Browse files
committed
Make selection a local varaible.
It is not use outside of this context.
1 parent 0e45b96 commit 3033817

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

zarr/indexing.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -882,23 +882,19 @@ class PartialChunkIterator:
882882
"""
883883

884884
def __init__(self, selection, arr_shape):
885-
## TODO: self.selection seem to be unused outside of this
886-
# and seem to be mutated; which might not be expected
887-
# self.selection seem to be expected to be part of the external API of
888-
# this iterator; so not sure we can make it a local variable.
889-
self.selection = make_slice_selection(selection)
885+
selection = make_slice_selection(selection)
890886
self.arr_shape = arr_shape
891887

892888
# number of selection dimensions can't be greater than the number of chunk dimensions
893-
if len(self.selection) > len(self.arr_shape):
889+
if len(selection) > len(self.arr_shape):
894890
raise ValueError(
895891
"Selection has more dimensions then the array:\n"
896-
"selection dimensions = {len(self.selection)\n"
892+
"selection dimensions = {len(selection)\n"
897893
"array dimensions = {len(self.arr_shape)}"
898894
)
899895

900896
# any selection can not be out of the range of the chunk
901-
selection_shape = np.empty(self.arr_shape)[tuple(self.selection)].shape
897+
selection_shape = np.empty(self.arr_shape)[tuple(selection)].shape
902898
if any(
903899
[
904900
selection_dim < 0 or selection_dim > arr_dim
@@ -911,16 +907,16 @@ def __init__(self, selection, arr_shape):
911907

912908
for i, dim_size in enumerate(self.arr_shape[::-1]):
913909
index = len(self.arr_shape) - (i + 1)
914-
if index <= len(self.selection) - 1:
910+
if index <= len(selection) - 1:
915911
slice_size = selection_shape[index]
916912
if slice_size == dim_size and index > 0:
917-
self.selection.pop()
913+
selection.pop()
918914
else:
919915
break
920916

921917
chunk_loc_slices = []
922-
last_dim_slice = None if self.selection[-1].step > 1 else self.selection.pop()
923-
for i, sl in enumerate(self.selection):
918+
last_dim_slice = None if selection[-1].step > 1 else selection.pop()
919+
for i, sl in enumerate(selection):
924920
dim_chunk_loc_slices = []
925921
for i, x in enumerate(slice_to_range(sl, arr_shape[i])):
926922
dim_chunk_loc_slices.append(slice(x, x + 1, 1))

0 commit comments

Comments
 (0)