Skip to content

Commit 62ec5b1

Browse files
STY: Use strict arg in zip() in pandas/tests/extension (#63294)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6fcb267 commit 62ec5b1

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

pandas/tests/extension/base/methods.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@ def test_combine_le(self, data_repeated):
350350
result = s1.combine(s2, lambda x1, x2: x1 <= x2)
351351
expected = pd.Series(
352352
pd.array(
353-
[a <= b for (a, b) in zip(list(orig_data1), list(orig_data2))],
353+
[
354+
a <= b
355+
for (a, b) in zip(list(orig_data1), list(orig_data2), strict=True)
356+
],
354357
dtype=self._combine_le_expected_dtype,
355358
)
356359
)
@@ -369,7 +372,7 @@ def test_combine_le(self, data_repeated):
369372
def _construct_for_combine_add(self, left, right):
370373
if isinstance(right, type(left)):
371374
return left._from_sequence(
372-
[a + b for (a, b) in zip(list(left), list(right))],
375+
[a + b for (a, b) in zip(list(left), list(right), strict=True)],
373376
dtype=left.dtype,
374377
)
375378
else:
@@ -627,7 +630,7 @@ def test_repeat(self, data, repeats, as_series, use_numpy):
627630
result = np.repeat(arr, repeats) if use_numpy else arr.repeat(repeats)
628631

629632
repeats = [repeats] * 3 if isinstance(repeats, int) else repeats
630-
expected = [x for x, n in zip(arr, repeats) for _ in range(n)]
633+
expected = [x for x, n in zip(arr, repeats, strict=True) for _ in range(n)]
631634
expected = type(data)._from_sequence(expected, dtype=data.dtype)
632635
if as_series:
633636
expected = pd.Series(expected, index=arr.index.repeat(repeats))

pandas/tests/extension/date/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __setitem__(self, key: int | slice | np.ndarray, value: Any) -> None:
162162
self._day[key] = value.day
163163

164164
def __repr__(self) -> str:
165-
return f"DateArray{list(zip(self._year, self._month, self._day))}"
165+
return f"DateArray{list(zip(self._year, self._month, self._day, strict=True))}"
166166

167167
def copy(self) -> DateArray:
168168
return DateArray((self._year.copy(), self._month.copy(), self._day.copy()))

pandas/tests/extension/decimal/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def convert_values(param):
295295

296296
# If the operator is not defined for the underlying objects,
297297
# a TypeError should be raised
298-
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]
298+
res = [op(a, b) for (a, b) in zip(lvalues, rvalues, strict=True)]
299299

300300
return np.asarray(res, dtype=bool)
301301

pandas/tests/extension/json/array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __getitem__(self, item):
128128
item = pd.api.indexers.check_array_indexer(self, item)
129129
if is_bool_dtype(item.dtype):
130130
return type(self)._from_sequence(
131-
[x for x, m in zip(self, item) if m], dtype=self.dtype
131+
[x for x, m in zip(self, item, strict=True) if m], dtype=self.dtype
132132
)
133133
# integer
134134
return type(self)([self.data[i] for i in item])
@@ -146,12 +146,12 @@ def __setitem__(self, key, value) -> None:
146146

147147
if isinstance(key, np.ndarray) and key.dtype == "bool":
148148
# masking
149-
for i, (k, v) in enumerate(zip(key, value)):
149+
for i, (k, v) in enumerate(zip(key, value, strict=False)):
150150
if k:
151151
assert isinstance(v, self.dtype.type)
152152
self.data[i] = v
153153
else:
154-
for k, v in zip(key, value):
154+
for k, v in zip(key, value, strict=False):
155155
assert isinstance(v, self.dtype.type)
156156
self.data[k] = v
157157

pandas/tests/extension/test_arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def _construct_for_combine_add(self, left, right):
282282

283283
if isinstance(right, type(left)):
284284
return left._from_sequence(
285-
[a + b for (a, b) in zip(list(left), list(right))],
285+
[a + b for (a, b) in zip(list(left), list(right), strict=True)],
286286
dtype=dtype,
287287
)
288288
else:

pandas/tests/extension/test_categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_combine_add(self, data_repeated):
126126
s2 = pd.Series(orig_data2)
127127
result = s1.combine(s2, lambda x1, x2: x1 + x2)
128128
expected = pd.Series(
129-
[a + b for (a, b) in zip(list(orig_data1), list(orig_data2))]
129+
[a + b for (a, b) in zip(list(orig_data1), list(orig_data2), strict=True)]
130130
)
131131
tm.assert_series_equal(result, expected)
132132

pandas/tests/extension/test_interval.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
def make_data(n: int):
3535
left_array = np.random.default_rng(2).uniform(size=n).cumsum()
3636
right_array = left_array + np.random.default_rng(2).uniform(size=n)
37-
return [Interval(left, right) for left, right in zip(left_array, right_array)]
37+
return [
38+
Interval(left, right)
39+
for left, right in zip(left_array, right_array, strict=True)
40+
]
3841

3942

4043
@pytest.fixture

0 commit comments

Comments
 (0)