diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 7f0cd51e4fcc9..d4f0e4681405b 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -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 @@ -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])) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index fcd7611b3e6b5..e8ca51ef92a94 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -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: @@ -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) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 2cc0a0ea6d101..d59499ed99c75 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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 ( @@ -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 @@ -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) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index c68b329b00968..7f5661f224348 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -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 diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index f09b70a359520..ace868bda52d3 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -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) diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index d20dc87259a37..57efde1a928bc 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -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: diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 180080da4cd00..adc09afab485b 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -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 @@ -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 diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index c04f3716f4739..e6ff67af78700 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -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": diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 64c2e1779aba7..1942212cd97b8 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -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: @@ -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: diff --git a/pyproject.toml b/pyproject.toml index f1eba171cde99..634b43c3897f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"]