Skip to content
Merged
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: 2 additions & 2 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def _cmp_method(self, other, op) -> ArrowExtensionArray:
boxed = self._box_pa(other)
except pa.lib.ArrowInvalid:
# e.g. GH#60228 [1, "b"] we have to operate pointwise
res_values = [op(x, y) for x, y in zip(self, other)]
res_values = [op(x, y) for x, y in zip(self, other, strict=True)]
result = pa.array(res_values, type=pa.bool_(), from_pandas=True)
else:
rtype = boxed.type
Expand Down Expand Up @@ -2713,7 +2713,7 @@ def _str_extract(self, pat: str, flags: int = 0, expand: bool = True):
if expand:
return {
col: self._from_pyarrow_array(pc.struct_field(result, [i]))
for col, i in zip(groups, range(result.type.num_fields))
for col, i in zip(groups, range(result.type.num_fields), strict=True)
}
else:
return type(self)(pc.struct_field(result, [0]))
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2869,7 +2869,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)]

def _maybe_convert(arr):
if coerce_to_dtype:
Expand All @@ -2885,7 +2885,7 @@ def _maybe_convert(arr):
return res

if op.__name__ in {"divmod", "rdivmod"}:
a, b = zip(*res)
a, b = zip(*res, strict=True)
return _maybe_convert(a), _maybe_convert(b)

return _maybe_convert(res)
Expand Down
10 changes: 7 additions & 3 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from csv import QUOTE_NONNUMERIC
from functools import partial
import itertools
import operator
from shutil import get_terminal_size
from typing import (
Expand Down Expand Up @@ -2429,8 +2430,8 @@ def _reverse_indexer(self) -> dict[Hashable, npt.NDArray[np.intp]]:
ensure_platform_int(self.codes), categories.size
)
counts = ensure_int64(counts).cumsum()
_result = (r[start:end] for start, end in zip(counts, counts[1:]))
return dict(zip(categories, _result))
_result = (r[start:end] for start, end in itertools.pairwise(counts))
return dict(zip(categories, _result, strict=True))

# ------------------------------------------------------------------
# Reductions
Expand Down Expand Up @@ -3165,5 +3166,8 @@ def factorize_from_iterables(iterables) -> tuple[list[np.ndarray], list[Index]]:
# For consistency, it should return two empty lists.
return [], []

codes, categories = zip(*(factorize_from_iterable(it) for it in iterables))
codes, categories = zip(
*(factorize_from_iterable(it) for it in iterables),
strict=True,
)
return list(codes), list(categories)
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2374,7 +2374,7 @@ def _concat_same_type(
to_concat = [x for x in to_concat if len(x)]

if obj.freq is not None and all(x.freq == obj.freq for x in to_concat):
pairs = zip(to_concat[:-1], to_concat[1:])
pairs = zip(to_concat[:-1], to_concat[1:], strict=True)
if all(pair[0][-1] + obj.freq == pair[1][0] for pair in pairs):
new_freq = obj.freq
new_obj._freq = new_freq
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
>>> idx.to_tuples()
Index([(0, 1), (1, 2)], dtype='object')
"""
tuples = com.asarray_tuplesafe(zip(self._left, self._right))
tuples = com.asarray_tuplesafe(zip(self._left, self._right, strict=True))
if not na_tuple:
# GH 18756
tuples = np.where(~self.isna(), tuples, np.nan)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def __iter__(self) -> Iterator:
yield val
else:
na_value = self.dtype.na_value
for isna_, val in zip(self._mask, self._data):
for isna_, val in zip(self._mask, self._data, strict=True):
if isna_:
yield na_value
else:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ def _range_from_fields(

freqstr = freq.freqstr
year, quarter = _make_field_arrays(year, quarter)
for y, q in zip(year, quarter):
for y, q in zip(year, quarter, strict=True):
calendar_year, calendar_month = parsing.quarter_to_myear(y, q, freqstr)
val = libperiod.period_ordinal(
calendar_year, calendar_month, 1, 1, 1, 1, 0, 0, base
Expand All @@ -1455,7 +1455,7 @@ def _range_from_fields(
freq = to_offset(freq, is_period=True)
base = libperiod.freq_to_dtype_code(freq)
arrays = _make_field_arrays(year, month, day, hour, minute, second)
for y, mth, d, h, mn, s in zip(*arrays):
for y, mth, d, h, mn, s in zip(*arrays, strict=True):
ordinals.append(libperiod.period_ordinal(y, mth, d, h, mn, s, 0, 0, base))

return np.array(ordinals, dtype=np.int64), freq
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
self._simple_new(
sp_value, self.sp_index, SparseDtype(sp_value.dtype, fv)
)
for sp_value, fv in zip(sp_values, fill_value)
for sp_value, fv in zip(sp_values, fill_value, strict=True)
)
return arrays
elif method == "reduce":
Expand Down
8 changes: 6 additions & 2 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ def __truediv__(self, other):
if is_object_dtype(other.dtype):
other = np.asarray(other)
if self.ndim > 1:
res_cols = [left / right for left, right in zip(self, other)]
res_cols = [
left / right for left, right in zip(self, other, strict=True)
]
res_cols2 = [x.reshape(1, -1) for x in res_cols]
result = np.concatenate(res_cols2, axis=0)
else:
Expand Down Expand Up @@ -670,7 +672,9 @@ def __floordiv__(self, other):
elif is_object_dtype(other.dtype):
other = np.asarray(other)
if self.ndim > 1:
res_cols = [left // right for left, right in zip(self, other)]
res_cols = [
left // right for left, right in zip(self, other, strict=True)
]
res_cols2 = [x.reshape(1, -1) for x in res_cols]
result = np.concatenate(res_cols2, axis=0)
else:
Expand Down
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,6 @@ exclude = [
"pandas/_config/config.py" = ["B905"]
"pandas/conftest.py" = ["B905"]
"pandas/core/array_algos/quantile.py" = ["B905"]
"pandas/core/arrays/arrow/array.py" = ["B905"]
"pandas/core/arrays/base.py" = ["B905"]
"pandas/core/arrays/categorical.py" = ["B905"]
"pandas/core/arrays/datetimelike.py" = ["B905"]
"pandas/core/arrays/interval.py" = ["B905"]
"pandas/core/arrays/masked.py" = ["B905"]
"pandas/core/arrays/period.py" = ["B905"]
"pandas/core/arrays/sparse/array.py" = ["B905"]
"pandas/core/arrays/timedeltas.py" = ["B905"]
"pandas/core/computation/align.py" = ["B905"]
"pandas/core/computation/expr.py" = ["B905"]
"pandas/core/computation/ops.py" = ["B905"]
Expand Down
Loading