Skip to content

Commit a366b8c

Browse files
committed
MAINT: Add strict=True to zip() in tests and fix related style issues
1 parent ba2cb48 commit a366b8c

File tree

136 files changed

+428
-282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+428
-282
lines changed

pandas/tests/apply/test_series_apply.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,9 @@ def test_apply_to_timedelta(by_row):
545545
)
546546
def test_apply_listlike_reducer(string_series, ops, names, how, kwargs):
547547
# GH 39140
548-
expected = Series({name: op(string_series) for name, op in zip(names, ops)})
548+
expected = Series(
549+
{name: op(string_series) for name, op in zip(names, ops, strict=True)}
550+
)
549551
expected.name = "series"
550552
result = getattr(string_series, how)(ops, **kwargs)
551553
tm.assert_series_equal(result, expected)

pandas/tests/arithmetic/test_interval.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def elementwise_comparison(self, op, interval_array, other):
107107
Helper that performs elementwise comparisons between `array` and `other`
108108
"""
109109
other = other if is_list_like(other) else [other] * len(interval_array)
110-
expected = np.array([op(x, y) for x, y in zip(interval_array, other)])
110+
expected = np.array(
111+
[op(x, y) for x, y in zip(interval_array, other, strict=True)]
112+
)
111113
if isinstance(other, Series):
112114
return Series(expected, index=other.index)
113115
return expected

pandas/tests/arithmetic/test_numeric.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def test_divmod_scalar(self, numeric_idx):
766766
div, mod = divmod(idx.values, 2)
767767

768768
expected = Index(div), Index(mod)
769-
for r, e in zip(result, expected):
769+
for r, e in zip(result, expected, strict=True):
770770
tm.assert_index_equal(r, e)
771771

772772
def test_divmod_ndarray(self, numeric_idx):
@@ -778,7 +778,7 @@ def test_divmod_ndarray(self, numeric_idx):
778778
div, mod = divmod(idx.values, other)
779779

780780
expected = Index(div), Index(mod)
781-
for r, e in zip(result, expected):
781+
for r, e in zip(result, expected, strict=True):
782782
tm.assert_index_equal(r, e)
783783

784784
def test_divmod_series(self, numeric_idx):
@@ -790,7 +790,7 @@ def test_divmod_series(self, numeric_idx):
790790
div, mod = divmod(idx.values, other)
791791

792792
expected = Series(div), Series(mod)
793-
for r, e in zip(result, expected):
793+
for r, e in zip(result, expected, strict=True):
794794
tm.assert_series_equal(r, e)
795795

796796
@pytest.mark.parametrize("other", [np.nan, 7, -23, 2.718, -3.14, np.inf])
@@ -1088,7 +1088,7 @@ def test_divmod(self, func):
10881088
with np.errstate(all="ignore"):
10891089
expecteds = divmod(series.values, np.asarray(other_np))
10901090

1091-
for result, expected in zip(results, expecteds):
1091+
for result, expected in zip(results, expecteds, strict=True):
10921092
# check the values, name, and index separately
10931093
tm.assert_almost_equal(np.asarray(result), expected)
10941094

pandas/tests/arithmetic/test_period.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,11 @@ def test_pi_add_sub_int_array_freqn_gt1(self):
962962
pi = period_range("2016-01-01", periods=10, freq="2D")
963963
arr = np.arange(10)
964964
result = pi + arr
965-
expected = pd.Index([x + y for x, y in zip(pi, arr)])
965+
expected = pd.Index([x + y for x, y in zip(pi, arr, strict=True)])
966966
tm.assert_index_equal(result, expected)
967967

968968
result = pi - arr
969-
expected = pd.Index([x - y for x, y in zip(pi, arr)])
969+
expected = pd.Index([x - y for x, y in zip(pi, arr, strict=True)])
970970
tm.assert_index_equal(result, expected)
971971

972972
def test_pi_sub_isub_offset(self):

pandas/tests/arrays/categorical/test_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_map_with_dict_or_series(na_action):
130130
expected = Categorical(new_values, categories=[3.0, 2, "one"])
131131
tm.assert_categorical_equal(result, expected)
132132

133-
mapper = dict(zip(orig_values[:-1], new_values[:-1]))
133+
mapper = dict(zip(orig_values[:-1], new_values[:-1], strict=True))
134134
result = cat.map(mapper, na_action=na_action)
135135
# Order of categories in result can be different
136136
tm.assert_categorical_equal(result, expected)

pandas/tests/arrays/integer/test_construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_conversions(data_missing):
6767
expected = np.array([pd.NA, 1], dtype=object)
6868
tm.assert_numpy_array_equal(result, expected)
6969

70-
for r, e in zip(result, expected):
70+
for r, e in zip(result, expected, strict=True):
7171
if pd.isnull(r):
7272
assert pd.isnull(e)
7373
elif is_integer(r):

pandas/tests/arrays/integer/test_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_ufunc_binary_output(using_nan_is_na):
104104
assert isinstance(result, tuple)
105105
assert len(result) == 2
106106

107-
for x, y in zip(result, expected):
107+
for x, y in zip(result, expected, strict=True):
108108
tm.assert_extension_array_equal(x, y)
109109

110110

pandas/tests/arrays/masked/test_arithmetic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
scalars += [False]
2020

2121

22-
@pytest.fixture(params=zip(arrays, scalars), ids=[a.dtype.name for a in arrays])
22+
@pytest.fixture(
23+
params=zip(arrays, scalars, strict=True), ids=[a.dtype.name for a in arrays]
24+
)
2325
def data(request):
2426
"""Fixture returning parametrized (array, scalar) tuple.
2527

pandas/tests/arrays/sparse/test_constructors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def test_constructor_object_dtype_bool_fill(self):
7777
assert arr.dtype == SparseDtype(object, False)
7878
assert arr.fill_value is False
7979
arr_expected = np.array(data, dtype=object)
80-
it = (type(x) == type(y) and x == y for x, y in zip(arr, arr_expected))
80+
it = (
81+
type(x) == type(y) and x == y
82+
for x, y in zip(arr, arr_expected, strict=True)
83+
)
8184
assert np.fromiter(it, dtype=np.bool_).all()
8285

8386
@pytest.mark.parametrize("dtype", [SparseDtype(int, 0), int])

pandas/tests/arrays/test_datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_iter(self, dta):
144144
def test_astype_object(self, dta):
145145
result = dta.astype(object)
146146
assert all(x._creso == dta._creso for x in result)
147-
assert all(x == y for x, y in zip(result, dta))
147+
assert all(x == y for x, y in zip(result, dta, strict=True))
148148

149149
def test_to_pydatetime(self, dta_dti):
150150
dta, dti = dta_dti

0 commit comments

Comments
 (0)