Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/tests/apply/test_series_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ def test_apply_to_timedelta(by_row):
)
def test_apply_listlike_reducer(string_series, ops, names, how, kwargs):
# GH 39140
expected = Series({name: op(string_series) for name, op in zip(names, ops)})
expected = Series(
{name: op(string_series) for name, op in zip(names, ops, strict=True)}
)
expected.name = "series"
result = getattr(string_series, how)(ops, **kwargs)
tm.assert_series_equal(result, expected)
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/arithmetic/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def elementwise_comparison(self, op, interval_array, other):
Helper that performs elementwise comparisons between `array` and `other`
"""
other = other if is_list_like(other) else [other] * len(interval_array)
expected = np.array([op(x, y) for x, y in zip(interval_array, other)])
expected = np.array(
[op(x, y) for x, y in zip(interval_array, other, strict=True)]
)
if isinstance(other, Series):
return Series(expected, index=other.index)
return expected
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def test_divmod_scalar(self, numeric_idx):
div, mod = divmod(idx.values, 2)

expected = Index(div), Index(mod)
for r, e in zip(result, expected):
for r, e in zip(result, expected, strict=True):
tm.assert_index_equal(r, e)

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

expected = Index(div), Index(mod)
for r, e in zip(result, expected):
for r, e in zip(result, expected, strict=True):
tm.assert_index_equal(r, e)

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

expected = Series(div), Series(mod)
for r, e in zip(result, expected):
for r, e in zip(result, expected, strict=True):
tm.assert_series_equal(r, e)

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

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

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/arithmetic/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,11 @@ def test_pi_add_sub_int_array_freqn_gt1(self):
pi = period_range("2016-01-01", periods=10, freq="2D")
arr = np.arange(10)
result = pi + arr
expected = pd.Index([x + y for x, y in zip(pi, arr)])
expected = pd.Index([x + y for x, y in zip(pi, arr, strict=True)])
tm.assert_index_equal(result, expected)

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

def test_pi_sub_isub_offset(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/categorical/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_map_with_dict_or_series(na_action):
expected = Categorical(new_values, categories=[3.0, 2, "one"])
tm.assert_categorical_equal(result, expected)

mapper = dict(zip(orig_values[:-1], new_values[:-1]))
mapper = dict(zip(orig_values[:-1], new_values[:-1], strict=True))
result = cat.map(mapper, na_action=na_action)
# Order of categories in result can be different
tm.assert_categorical_equal(result, expected)
2 changes: 1 addition & 1 deletion pandas/tests/arrays/integer/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_conversions(data_missing):
expected = np.array([pd.NA, 1], dtype=object)
tm.assert_numpy_array_equal(result, expected)

for r, e in zip(result, expected):
for r, e in zip(result, expected, strict=True):
if pd.isnull(r):
assert pd.isnull(e)
elif is_integer(r):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/integer/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_ufunc_binary_output(using_nan_is_na):
assert isinstance(result, tuple)
assert len(result) == 2

for x, y in zip(result, expected):
for x, y in zip(result, expected, strict=True):
tm.assert_extension_array_equal(x, y)


Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/arrays/masked/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
scalars += [False]


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

Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/arrays/sparse/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def test_constructor_object_dtype_bool_fill(self):
assert arr.dtype == SparseDtype(object, False)
assert arr.fill_value is False
arr_expected = np.array(data, dtype=object)
it = (type(x) == type(y) and x == y for x, y in zip(arr, arr_expected))
it = (
type(x) == type(y) and x == y
for x, y in zip(arr, arr_expected, strict=True)
)
assert np.fromiter(it, dtype=np.bool_).all()

@pytest.mark.parametrize("dtype", [SparseDtype(int, 0), int])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_iter(self, dta):
def test_astype_object(self, dta):
result = dta.astype(object)
assert all(x._creso == dta._creso for x in result)
assert all(x == y for x, y in zip(result, dta))
assert all(x == y for x, y in zip(result, dta, strict=True))

def test_to_pydatetime(self, dta_dti):
dta, dti = dta_dti
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/base/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_iter_box_dt64(self, unit):
vals = [Timestamp("2011-01-01"), Timestamp("2011-01-02")]
ser = Series(vals).dt.as_unit(unit)
assert ser.dtype == f"datetime64[{unit}]"
for res, exp in zip(ser, vals):
for res, exp in zip(ser, vals, strict=True):
assert isinstance(res, Timestamp)
assert res.tz is None
assert res == exp
Expand All @@ -164,7 +164,7 @@ def test_iter_box_dt64tz(self, unit):
ser = Series(vals).dt.as_unit(unit)

assert ser.dtype == f"datetime64[{unit}, US/Eastern]"
for res, exp in zip(ser, vals):
for res, exp in zip(ser, vals, strict=True):
assert isinstance(res, Timestamp)
assert res.tz == exp.tz
assert res == exp
Expand All @@ -175,7 +175,7 @@ def test_iter_box_timedelta64(self, unit):
vals = [Timedelta("1 days"), Timedelta("2 days")]
ser = Series(vals).dt.as_unit(unit)
assert ser.dtype == f"timedelta64[{unit}]"
for res, exp in zip(ser, vals):
for res, exp in zip(ser, vals, strict=True):
assert isinstance(res, Timedelta)
assert res == exp
assert res.unit == unit
Expand All @@ -185,7 +185,7 @@ def test_iter_box_period(self):
vals = [pd.Period("2011-01-01", freq="M"), pd.Period("2011-01-02", freq="M")]
s = Series(vals)
assert s.dtype == "Period[M]"
for res, exp in zip(s, vals):
for res, exp in zip(s, vals, strict=True):
assert isinstance(res, pd.Period)
assert res.freq == "ME"
assert res == exp
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ def test_attr_expression(self):
expec3 = df.a + df.b + df.c[df.b < 0]
exprs = expr1, expr2, expr3
expecs = expec1, expec2, expec3
for e, expec in zip(exprs, expecs):
for e, expec in zip(exprs, expecs, strict=True):
tm.assert_series_equal(expec, self.eval(e, local_dict={"df": df}))

def test_assignment_fails(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/copy_view/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,5 @@ def test_join_multiple_dataframes_on_key():
assert not np.shares_memory(get_array(result, "c"), get_array(dfs_list[1], "c"))

tm.assert_frame_equal(df1, df1_orig)
for df, df_orig in zip(dfs_list, dfs_list_orig):
for df, df_orig in zip(dfs_list, dfs_list_orig, strict=True):
tm.assert_frame_equal(df, df_orig)
4 changes: 2 additions & 2 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ def shape(self):
(np.nan, False, "NaN"),
(None, False, "None"),
]
objs, expected, ids = zip(*ll_params)
objs, expected, ids = zip(*ll_params, strict=True)


@pytest.fixture(params=zip(objs, expected), ids=ids)
@pytest.fixture(params=zip(objs, expected, strict=True), ids=ids)
def maybe_list_like(request):
return request.param

Expand Down
7 changes: 5 additions & 2 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ def test_combine_le(self, data_repeated):
result = s1.combine(s2, lambda x1, x2: x1 <= x2)
expected = pd.Series(
pd.array(
[a <= b for (a, b) in zip(list(orig_data1), list(orig_data2))],
[
a <= b
for (a, b) in zip(list(orig_data1), list(orig_data2), strict=True)
],
dtype=self._combine_le_expected_dtype,
)
)
Expand All @@ -369,7 +372,7 @@ def test_combine_le(self, data_repeated):
def _construct_for_combine_add(self, left, right):
if isinstance(right, type(left)):
return left._from_sequence(
[a + b for (a, b) in zip(list(left), list(right))],
[a + b for (a, b) in zip(list(left), list(right), strict=True)],
dtype=left.dtype,
)
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/date/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __setitem__(self, key: int | slice | np.ndarray, value: Any) -> None:
self._day[key] = value.day

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

def copy(self) -> DateArray:
return DateArray((self._year.copy(), self._month.copy(), self._day.copy()))
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def convert_values(param):

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

return np.asarray(res, dtype=bool)

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __getitem__(self, item):
item = pd.api.indexers.check_array_indexer(self, item)
if is_bool_dtype(item.dtype):
return type(self)._from_sequence(
[x for x, m in zip(self, item) if m], dtype=self.dtype
[x for x, m in zip(self, item, strict=True) if m], dtype=self.dtype
)
# integer
return type(self)([self.data[i] for i in item])
Expand All @@ -135,12 +135,12 @@ def __setitem__(self, key, value) -> None:

if isinstance(key, np.ndarray) and key.dtype == "bool":
# masking
for i, (k, v) in enumerate(zip(key, value)):
for i, (k, v) in enumerate(zip(key, value, strict=False)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When value is assigned to cycle it should be strict=False otherwise, I think it can be strict=True.

if k:
assert isinstance(v, self.dtype.type)
self.data[i] = v
else:
for k, v in zip(key, value):
for k, v in zip(key, value, strict=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

assert isinstance(v, self.dtype.type)
self.data[k] = v

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def _construct_for_combine_add(self, left, right):

if isinstance(right, type(left)):
return left._from_sequence(
[a + b for (a, b) in zip(list(left), list(right))],
[a + b for (a, b) in zip(list(left), list(right), strict=True)],
dtype=dtype,
)
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_combine_add(self, data_repeated):
s2 = pd.Series(orig_data2)
result = s1.combine(s2, lambda x1, x2: x1 + x2)
expected = pd.Series(
[a + b for (a, b) in zip(list(orig_data1), list(orig_data2))]
[a + b for (a, b) in zip(list(orig_data1), list(orig_data2), strict=True)]
)
tm.assert_series_equal(result, expected)

Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/extension/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
def make_data(n: int):
left_array = np.random.default_rng(2).uniform(size=n).cumsum()
right_array = left_array + np.random.default_rng(2).uniform(size=n)
return [Interval(left, right) for left, right in zip(left_array, right_array)]
return [
Interval(left, right)
for left, right in zip(left_array, right_array, strict=True)
]


@pytest.fixture
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/frame/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def mixed_float_frame():
{
col: np.random.default_rng(2).random(30, dtype=dtype)
for col, dtype in zip(
list("ABCD"), ["float32", "float32", "float32", "float64"]
list("ABCD"), ["float32", "float32", "float32", "float64"], strict=True
)
},
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
Expand All @@ -70,7 +70,9 @@ def mixed_int_frame():
return DataFrame(
{
col: np.ones(30, dtype=dtype)
for col, dtype in zip(list("ABCD"), ["int32", "uint64", "uint8", "int64"])
for col, dtype in zip(
list("ABCD"), ["int32", "uint64", "uint8", "int64"], strict=True
)
},
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
)
Expand Down
16 changes: 8 additions & 8 deletions pandas/tests/frame/constructors/test_from_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ def test_constructor_list_of_odicts(self):

result = DataFrame(data)
expected = DataFrame.from_dict(
dict(zip(range(len(data)), data)), orient="index"
dict(zip(range(len(data)), data, strict=True)), orient="index"
)
tm.assert_frame_equal(result, expected.reindex(result.index))

def test_constructor_single_row(self):
data = [OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]])]

result = DataFrame(data)
expected = DataFrame.from_dict(dict(zip([0], data)), orient="index").reindex(
result.index
)
expected = DataFrame.from_dict(
dict(zip([0], data, strict=True)), orient="index"
).reindex(result.index)
tm.assert_frame_equal(result, expected)

def test_constructor_list_of_series(self):
data = [
OrderedDict([["a", 1.5], ["b", 3.0], ["c", 4.0]]),
OrderedDict([["a", 1.5], ["b", 3.0], ["c", 6.0]]),
]
sdict = OrderedDict(zip(["x", "y"], data))
sdict = OrderedDict(zip(["x", "y"], data, strict=True))
idx = Index(["a", "b", "c"])

# all named
Expand All @@ -66,7 +66,7 @@ def test_constructor_list_of_series(self):
]
result = DataFrame(data2)

sdict = OrderedDict(zip(["x", "Unnamed 0"], data))
sdict = OrderedDict(zip(["x", "Unnamed 0"], data, strict=True))
expected = DataFrame.from_dict(sdict, orient="index")
tm.assert_frame_equal(result, expected)

Expand All @@ -82,7 +82,7 @@ def test_constructor_list_of_series(self):
data = [Series(d) for d in data]

result = DataFrame(data)
sdict = OrderedDict(zip(range(len(data)), data))
sdict = OrderedDict(zip(range(len(data)), data, strict=True))
expected = DataFrame.from_dict(sdict, orient="index")
tm.assert_frame_equal(result, expected.reindex(result.index))

Expand All @@ -97,7 +97,7 @@ def test_constructor_list_of_series(self):
OrderedDict([["a", 1.5], ["b", 3.0], ["c", 4.0]]),
OrderedDict([["a", 1.5], ["b", 3.0], ["c", 6.0]]),
]
sdict = OrderedDict(zip(range(len(data)), data))
sdict = OrderedDict(zip(range(len(data)), data, strict=True))

idx = Index(["a", "b", "c"])
data2 = [Series([1.5, 3, 4], idx, dtype="O"), Series([1.5, 3, 6], idx)]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_delitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_delitem_corner(self, float_frame):
def test_delitem_col_still_multiindex(self):
arrays = [["a", "b", "c", "top"], ["", "", "", "OD"], ["", "", "", "wx"]]

tuples = sorted(zip(*arrays))
tuples = sorted(zip(*arrays, strict=True))
index = MultiIndex.from_tuples(tuples)

df = DataFrame(np.random.default_rng(2).standard_normal((3, 4)), columns=index)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/indexing/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def test_getitem_dupe_cols(self):
iter,
Index,
set,
lambda keys: dict(zip(keys, range(len(keys)))),
lambda keys: dict(zip(keys, range(len(keys)))).keys(),
lambda keys: dict(zip(keys, range(len(keys)), strict=True)),
lambda keys: dict(zip(keys, range(len(keys)), strict=True)).keys(),
],
ids=["list", "iter", "Index", "set", "dict", "dict_keys"],
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ def test_big_endian_support_selecting_columns(self):
# GH#57457
columns = ["a"]
data = [np.array([1, 2], dtype=">f8")]
df = DataFrame(dict(zip(columns, data)))
df = DataFrame(dict(zip(columns, data, strict=True)))
result = df[df.columns]
dfexp = DataFrame({"a": [1, 2]}, dtype=">f8")
expected = dfexp[dfexp.columns]
Expand Down
Loading
Loading