Skip to content

Commit e704151

Browse files
committed
STY: Use strict arg in zip() in pandas/tests/extension
I added strict=True parameter to 11 zip() calls across 7 files in the pandas/tests/extension directory to enforce Ruff rule B905. This ensures that all zipped iterables have equal lengths, making the tests more robust and catching potential bugs early during testing. Files modified: - base/methods.py: 3 zip() calls - date/array.py: 1 zip() call - decimal/array.py: 1 zip() call - json/array.py: 3 zip() calls - test_arrow.py: 1 zip() call - test_categorical.py: 1 zip() call - test_interval.py: 1 zip() call
1 parent 311f92e commit e704151

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

pandas/tests/extension/base/methods.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ 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+
[a <= b for (a, b) in zip(list(orig_data1), list(orig_data2), strict=True)],
354354
dtype=self._combine_le_expected_dtype,
355355
)
356356
)
@@ -369,7 +369,7 @@ def test_combine_le(self, data_repeated):
369369
def _construct_for_combine_add(self, left, right):
370370
if isinstance(right, type(left)):
371371
return left._from_sequence(
372-
[a + b for (a, b) in zip(list(left), list(right))],
372+
[a + b for (a, b) in zip(list(left), list(right), strict=True)],
373373
dtype=left.dtype,
374374
)
375375
else:
@@ -627,7 +627,7 @@ def test_repeat(self, data, repeats, as_series, use_numpy):
627627
result = np.repeat(arr, repeats) if use_numpy else arr.repeat(repeats)
628628

629629
repeats = [repeats] * 3 if isinstance(repeats, int) else repeats
630-
expected = [x for x, n in zip(arr, repeats) for _ in range(n)]
630+
expected = [x for x, n in zip(arr, repeats, strict=True) for _ in range(n)]
631631
expected = type(data)._from_sequence(expected, dtype=data.dtype)
632632
if as_series:
633633
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=True)):
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=True):
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
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 [Interval(left, right) for left, right in zip(left_array, right_array, strict=True)]
3838

3939

4040
@pytest.fixture

0 commit comments

Comments
 (0)