Skip to content

Commit 77d5a99

Browse files
committed
Make ruff fixes for Python 3.10
1 parent 7cdc497 commit 77d5a99

File tree

12 files changed

+92
-47
lines changed

12 files changed

+92
-47
lines changed

zarr/_storage/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def set_partial_values(self, key_start_values):
352352
Also, start may only be beyond the current value if other values fill the gap.
353353
start may be negative to start writing start bytes from the current
354354
end of the file, ending the file with the new value."""
355-
unique_keys = set(next(zip(*key_start_values)))
355+
unique_keys = set(next(zip(*key_start_values, strict=False)))
356356
values = {}
357357
for key in unique_keys:
358358
old_value = self.get(key)

zarr/_storage/v3_storage_transformers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class _ShardIndex(NamedTuple):
3232

3333
def __localize_chunk__(self, chunk: Tuple[int, ...]) -> Tuple[int, ...]:
3434
return tuple(
35-
chunk_i % shard_i for chunk_i, shard_i in zip(chunk, self.store.chunks_per_shard)
35+
chunk_i % shard_i
36+
for chunk_i, shard_i in zip(chunk, self.store.chunks_per_shard, strict=False)
3637
)
3738

3839
def is_all_empty(self) -> bool:
@@ -137,7 +138,8 @@ def _key_to_shard(self, chunk_key: str) -> Tuple[str, Tuple[int, ...]]:
137138
tuple(map(int, chunk_string.split(self.dimension_separator))) if chunk_string else (0,)
138139
)
139140
shard_key_tuple = (
140-
subkey // shard_i for subkey, shard_i in zip(chunk_subkeys, self.chunks_per_shard)
141+
subkey // shard_i
142+
for subkey, shard_i in zip(chunk_subkeys, self.chunks_per_shard, strict=False)
141143
)
142144
shard_key = prefix + "c" + self.dimension_separator.join(map(str, shard_key_tuple))
143145
return shard_key, chunk_subkeys
@@ -167,7 +169,7 @@ def _get_chunks_in_shard(self, shard_key: str) -> Iterator[Tuple[int, ...]]:
167169
yield tuple(
168170
shard_key_i * shards_i + offset_i
169171
for shard_key_i, offset_i, shards_i in zip(
170-
shard_key_tuple, chunk_offset, self.chunks_per_shard
172+
shard_key_tuple, chunk_offset, self.chunks_per_shard, strict=False
171173
)
172174
)
173175

@@ -240,7 +242,9 @@ def __setitem__(self, key, value):
240242
for _, chunk_slice in valid_chunk_slices
241243
]
242244
)
243-
for chunk_value, (chunk_to_read, _) in zip(chunk_values, valid_chunk_slices):
245+
for chunk_value, (chunk_to_read, _) in zip(
246+
chunk_values, valid_chunk_slices, strict=False
247+
):
244248
new_content[chunk_to_read] = chunk_value
245249
else:
246250
if full_shard_value is None:

zarr/convenience.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,12 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10131013
# everything into memory
10141014
shape = ds.shape
10151015
chunks = ds.chunks
1016-
chunk_offsets = [range(0, s, c) for s, c in zip(shape, chunks)]
1016+
chunk_offsets = [range(0, s, c) for s, c in zip(shape, chunks, strict=False)]
10171017
for offset in itertools.product(*chunk_offsets):
1018-
sel = tuple(slice(o, min(s, o + c)) for o, s, c in zip(offset, shape, chunks))
1018+
sel = tuple(
1019+
slice(o, min(s, o + c))
1020+
for o, s, c in zip(offset, shape, chunks, strict=False)
1021+
)
10191022
ds[sel] = source[sel]
10201023
n_bytes_copied += ds.size * ds.dtype.itemsize
10211024

zarr/core.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def _cdata_shape(self):
477477
if self._shape == ():
478478
return (1,)
479479
else:
480-
return tuple(math.ceil(s / c) for s, c in zip(self._shape, self._chunks))
480+
return tuple(math.ceil(s / c) for s, c in zip(self._shape, self._chunks, strict=False))
481481

482482
@property
483483
def cdata_shape(self):
@@ -1339,7 +1339,7 @@ def _get_selection(self, indexer, out=None, fields=None):
13391339

13401340
if math.prod(out_shape) > 0:
13411341
# allow storage to get multiple items at once
1342-
lchunk_coords, lchunk_selection, lout_selection = zip(*indexer)
1342+
lchunk_coords, lchunk_selection, lout_selection = zip(*indexer, strict=False)
13431343
self._chunk_getitems(
13441344
lchunk_coords,
13451345
lchunk_selection,
@@ -1990,7 +1990,7 @@ def _set_selection(self, indexer, value, fields=None):
19901990
# put data
19911991
self._chunk_setitem(chunk_coords, chunk_selection, chunk_value, fields=fields)
19921992
else:
1993-
lchunk_coords, lchunk_selection, lout_selection = zip(*indexer)
1993+
lchunk_coords, lchunk_selection, lout_selection = zip(*indexer, strict=False)
19941994
chunk_values = []
19951995
for out_selection in lout_selection:
19961996
if sel_shape == ():
@@ -2170,15 +2170,19 @@ def _chunk_getitems(
21702170
elif hasattr(self.chunk_store, "get_partial_values"):
21712171
partial_read_decode = False
21722172
values = self.chunk_store.get_partial_values([(ckey, (0, None)) for ckey in ckeys])
2173-
cdatas = {key: value for key, value in zip(ckeys, values) if value is not None}
2173+
cdatas = {
2174+
key: value for key, value in zip(ckeys, values, strict=False) if value is not None
2175+
}
21742176
else:
21752177
partial_read_decode = False
21762178
contexts = {}
21772179
if not isinstance(self._meta_array, np.ndarray):
21782180
contexts = ConstantMap(ckeys, constant=Context(meta_array=self._meta_array))
21792181
cdatas = self.chunk_store.getitems(ckeys, contexts=contexts)
21802182

2181-
for ckey, chunk_select, out_select in zip(ckeys, lchunk_selection, lout_selection):
2183+
for ckey, chunk_select, out_select in zip(
2184+
ckeys, lchunk_selection, lout_selection, strict=False
2185+
):
21822186
if ckey in cdatas:
21832187
self._process_chunk(
21842188
out,
@@ -2203,7 +2207,7 @@ def _chunk_setitems(self, lchunk_coords, lchunk_selection, values, fields=None):
22032207
ckeys = map(self._chunk_key, lchunk_coords)
22042208
cdatas = {
22052209
key: self._process_for_setitem(key, sel, val, fields=fields)
2206-
for key, sel, val in zip(ckeys, lchunk_selection, values)
2210+
for key, sel, val in zip(ckeys, lchunk_selection, values, strict=False)
22072211
}
22082212
to_store = {}
22092213
if not self.write_empty_chunks:
@@ -2636,7 +2640,7 @@ def _resize_nosync(self, *args):
26362640

26372641
# determine the new number and arrangement of chunks
26382642
chunks = self._chunks
2639-
new_cdata_shape = tuple(math.ceil(s / c) for s, c in zip(new_shape, chunks))
2643+
new_cdata_shape = tuple(math.ceil(s / c) for s, c in zip(new_shape, chunks, strict=False))
26402644

26412645
# remove any chunks not within range
26422646
# The idea is that, along each dimension,
@@ -2647,13 +2651,13 @@ def _resize_nosync(self, *args):
26472651
chunk_store = self.chunk_store
26482652
old_cdata_shape_working_list = list(old_cdata_shape)
26492653
for idx_cdata, (val_old_cdata, val_new_cdata) in enumerate(
2650-
zip(old_cdata_shape_working_list, new_cdata_shape)
2654+
zip(old_cdata_shape_working_list, new_cdata_shape, strict=False)
26512655
):
26522656
for cidx in itertools.product(
26532657
*[
26542658
range(n_new, n_old) if (idx == idx_cdata) else range(n_old)
26552659
for idx, (n_old, n_new) in enumerate(
2656-
zip(old_cdata_shape_working_list, new_cdata_shape)
2660+
zip(old_cdata_shape_working_list, new_cdata_shape, strict=False)
26572661
)
26582662
]
26592663
):

zarr/indexing.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ def __init__(self, selection, array):
331331

332332
# setup per-dimension indexers
333333
dim_indexers = []
334-
for dim_sel, dim_len, dim_chunk_len in zip(selection, array._shape, array._chunks):
334+
for dim_sel, dim_len, dim_chunk_len in zip(
335+
selection, array._shape, array._chunks, strict=False
336+
):
335337
if is_integer(dim_sel):
336338
dim_indexer = IntDimIndexer(dim_sel, dim_len, dim_chunk_len)
337339

@@ -552,7 +554,7 @@ def ix_(selection, shape):
552554
if isinstance(dim_sel, slice)
553555
else [dim_sel] if is_integer(dim_sel) else dim_sel
554556
)
555-
for dim_sel, dim_len in zip(selection, shape)
557+
for dim_sel, dim_len in zip(selection, shape, strict=False)
556558
]
557559

558560
# now get numpy to convert to a coordinate selection
@@ -597,7 +599,9 @@ def __init__(self, selection, array):
597599

598600
# setup per-dimension indexers
599601
dim_indexers = []
600-
for dim_sel, dim_len, dim_chunk_len in zip(selection, array._shape, array._chunks):
602+
for dim_sel, dim_len, dim_chunk_len in zip(
603+
selection, array._shape, array._chunks, strict=False
604+
):
601605
if is_integer(dim_sel):
602606
dim_indexer = IntDimIndexer(dim_sel, dim_len, dim_chunk_len)
603607

@@ -683,7 +687,9 @@ def __init__(self, selection, array):
683687

684688
# setup per-dimension indexers
685689
dim_indexers = []
686-
for dim_sel, dim_len, dim_chunk_size in zip(selection, array._shape, array._chunks):
690+
for dim_sel, dim_len, dim_chunk_size in zip(
691+
selection, array._shape, array._chunks, strict=False
692+
):
687693
dim_numchunks = int(np.ceil(dim_len / dim_chunk_size))
688694

689695
if is_integer(dim_sel):
@@ -790,7 +796,7 @@ def __init__(self, selection, array):
790796
)
791797

792798
# handle wraparound, boundscheck
793-
for dim_sel, dim_len in zip(selection, array.shape):
799+
for dim_sel, dim_len in zip(selection, array.shape, strict=False):
794800
# handle wraparound
795801
wraparound_indices(dim_sel, dim_len)
796802

@@ -799,7 +805,8 @@ def __init__(self, selection, array):
799805

800806
# compute chunk index for each point in the selection
801807
chunks_multi_index = tuple(
802-
dim_sel // dim_chunk_len for (dim_sel, dim_chunk_len) in zip(selection, array._chunks)
808+
dim_sel // dim_chunk_len
809+
for (dim_sel, dim_chunk_len) in zip(selection, array._chunks, strict=False)
803810
)
804811

805812
# broadcast selection - this will raise error if array dimensions don't match
@@ -856,11 +863,13 @@ def __iter__(self):
856863

857864
chunk_offsets = tuple(
858865
dim_chunk_ix * dim_chunk_len
859-
for dim_chunk_ix, dim_chunk_len in zip(chunk_coords, self.array._chunks)
866+
for dim_chunk_ix, dim_chunk_len in zip(
867+
chunk_coords, self.array._chunks, strict=False
868+
)
860869
)
861870
chunk_selection = tuple(
862871
dim_sel[start:stop] - dim_chunk_offset
863-
for (dim_sel, dim_chunk_offset) in zip(self.selection, chunk_offsets)
872+
for (dim_sel, dim_chunk_offset) in zip(self.selection, chunk_offsets, strict=False)
864873
)
865874

866875
yield ChunkProjection(chunk_coords, chunk_selection, out_selection)
@@ -1040,7 +1049,7 @@ def __init__(self, selection, arr_shape):
10401049
selection_shape = np.empty(self.arr_shape)[tuple(selection)].shape
10411050
if any(
10421051
selection_dim < 0 or selection_dim > arr_dim
1043-
for selection_dim, arr_dim in zip(selection_shape, self.arr_shape)
1052+
for selection_dim, arr_dim in zip(selection_shape, self.arr_shape, strict=False)
10441053
):
10451054
raise IndexError(
10461055
"a selection index is out of range for the dimension"
@@ -1057,7 +1066,7 @@ def __init__(self, selection, arr_shape):
10571066

10581067
chunk_loc_slices = []
10591068
last_dim_slice = None if selection[-1].step > 1 else selection.pop()
1060-
for arr_shape_i, sl in zip(arr_shape, selection):
1069+
for arr_shape_i, sl in zip(arr_shape, selection, strict=False):
10611070
dim_chunk_loc_slices = []
10621071
assert isinstance(sl, slice)
10631072
for x in slice_to_range(sl, arr_shape_i):

zarr/tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ def compare_arrays(expected, actual, item_dtype):
13841384
assert isinstance(actual, np.ndarray)
13851385
assert actual.dtype == object
13861386
assert actual.shape == expected.shape
1387-
for ev, av in zip(expected.flat, actual.flat):
1387+
for ev, av in zip(expected.flat, actual.flat, strict=False):
13881388
assert isinstance(av, np.ndarray)
13891389
assert_array_equal(ev, av)
13901390
assert av.dtype == item_dtype

zarr/tests/test_hierarchy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,9 @@ def test_getitem_contains_iterators(self):
647647
values = list(g1.values())
648648
if g1._version == 3:
649649
# v3 are not automatically sorted by key
650-
items, values = zip(*sorted(zip(items, values), key=lambda x: x[0]))
650+
items, values = zip(
651+
*sorted(zip(items, values, strict=False), key=lambda x: x[0]), strict=False
652+
)
651653
assert "a" == items[0][0]
652654
assert g1["a"] == items[0][1]
653655
assert g1["a"] == values[0]
@@ -659,7 +661,9 @@ def test_getitem_contains_iterators(self):
659661
values = list(g1["foo"].values())
660662
if g1._version == 3:
661663
# v3 are not automatically sorted by key
662-
items, values = zip(*sorted(zip(items, values), key=lambda x: x[0]))
664+
items, values = zip(
665+
*sorted(zip(items, values, strict=False), key=lambda x: x[0]), strict=False
666+
)
663667
assert "bar" == items[0][0]
664668
assert g1["foo"]["bar"] == items[0][1]
665669
assert g1["foo"]["bar"] == values[0]

zarr/tests/test_indexing.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,9 @@ def test_get_block_selection_1d():
10921092
z = zarr.create(shape=a.shape, chunks=100, dtype=a.dtype)
10931093
z[:] = a
10941094

1095-
for selection, expected_idx in zip(block_selections_1d, block_selections_1d_array_projection):
1095+
for selection, expected_idx in zip(
1096+
block_selections_1d, block_selections_1d_array_projection, strict=False
1097+
):
10961098
_test_get_block_selection(a, z, selection, expected_idx)
10971099

10981100
bad_selections = block_selections_1d_bad + [
@@ -1144,7 +1146,9 @@ def test_get_block_selection_2d():
11441146
z = zarr.create(shape=a.shape, chunks=(300, 3), dtype=a.dtype)
11451147
z[:] = a
11461148

1147-
for selection, expected_idx in zip(block_selections_2d, block_selections_2d_array_projection):
1149+
for selection, expected_idx in zip(
1150+
block_selections_2d, block_selections_2d_array_projection, strict=False
1151+
):
11481152
_test_get_block_selection(a, z, selection, expected_idx)
11491153

11501154
with pytest.raises(IndexError):
@@ -1179,7 +1183,9 @@ def test_set_block_selection_1d():
11791183
a = np.empty(v.shape, dtype=v.dtype)
11801184
z = zarr.create(shape=a.shape, chunks=100, dtype=a.dtype)
11811185

1182-
for selection, expected_idx in zip(block_selections_1d, block_selections_1d_array_projection):
1186+
for selection, expected_idx in zip(
1187+
block_selections_1d, block_selections_1d_array_projection, strict=False
1188+
):
11831189
_test_set_block_selection(v, a, z, selection, expected_idx)
11841190

11851191
for selection in block_selections_1d_bad:
@@ -1195,7 +1201,9 @@ def test_set_block_selection_2d():
11951201
a = np.empty(v.shape, dtype=v.dtype)
11961202
z = zarr.create(shape=a.shape, chunks=(300, 3), dtype=a.dtype)
11971203

1198-
for selection, expected_idx in zip(block_selections_2d, block_selections_2d_array_projection):
1204+
for selection, expected_idx in zip(
1205+
block_selections_2d, block_selections_2d_array_projection, strict=False
1206+
):
11991207
_test_set_block_selection(v, a, z, selection, expected_idx)
12001208

12011209
with pytest.raises(IndexError):
@@ -1720,7 +1728,8 @@ def test_accessed_chunks(shape, chunks, ops):
17201728
for ii, (optype, slices) in enumerate(ops):
17211729
# Resolve the slices into the accessed chunks for each dimension
17221730
chunks_per_dim = [
1723-
np.unique(np.arange(N, dtype=int)[sl] // C) for N, C, sl in zip(shape, chunks, slices)
1731+
np.unique(np.arange(N, dtype=int)[sl] // C)
1732+
for N, C, sl in zip(shape, chunks, slices, strict=False)
17241733
]
17251734

17261735
# Combine and generate the cartesian product to determine the chunks keys that

zarr/tests/test_storage.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,9 +1622,10 @@ def test_filters(self):
16221622
(None, does_not_raise()),
16231623
([], does_not_raise()),
16241624
([AsType("f4", "f8")], pytest.raises(ValueError)),
1625-
]
1625+
],
1626+
strict=False,
16261627
)
1627-
for filters, error in zip(all_filters, all_errors):
1628+
for filters, error in zip(all_filters, all_errors, strict=False):
16281629
store = self.create_store()
16291630
with error:
16301631
init_array(store, shape=1000, chunks=100, filters=filters)
@@ -1761,9 +1762,10 @@ def test_filters(self):
17611762
(None, does_not_raise()),
17621763
([], does_not_raise()),
17631764
([AsType("f4", "f8")], pytest.raises(ValueError)),
1764-
]
1765+
],
1766+
strict=False,
17651767
)
1766-
for filters, error in zip(all_filters, all_errors):
1768+
for filters, error in zip(all_filters, all_errors, strict=False):
17671769
store = self.create_store()
17681770
with error:
17691771
init_array(store, shape=1000, chunks=100, filters=filters)
@@ -2476,7 +2478,7 @@ def test_iterators_with_prefix(self):
24762478
assert 4 == len(store)
24772479
keys = [prefix + "a", prefix + "b", prefix + "c/d", prefix + "c/e/f"]
24782480
values = [b"aaa", b"bbb", b"ddd", b"fff"]
2479-
items = list(zip(keys, values))
2481+
items = list(zip(keys, values, strict=False))
24802482
assert set(keys) == set(store)
24812483
assert set(keys) == set(store.keys())
24822484
assert set(values) == set(store.values())

0 commit comments

Comments
 (0)