From b8a0fc932c628ae3ef55964f595e416e36e0d4a7 Mon Sep 17 00:00:00 2001 From: Zorex Salvo Date: Sun, 26 Oct 2025 10:07:29 +0800 Subject: [PATCH 1/2] STY: use strict zip in `pandas/tests/window` --- pandas/tests/window/test_cython_aggregations.py | 2 +- pandas/tests/window/test_expanding.py | 4 ++-- pandas/tests/window/test_rolling.py | 15 +++++++++------ pyproject.toml | 3 --- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pandas/tests/window/test_cython_aggregations.py b/pandas/tests/window/test_cython_aggregations.py index 39811ea3ec5b9..f5f33d889da75 100644 --- a/pandas/tests/window/test_cython_aggregations.py +++ b/pandas/tests/window/test_cython_aggregations.py @@ -62,7 +62,7 @@ def _get_rolling_aggregations(): ] ) # unzip to a list of 2 tuples, names and functions - unzipped = list(zip(*named_roll_aggs)) + unzipped = list(zip(*named_roll_aggs, strict=False)) return {"ids": unzipped[0], "params": unzipped[1]} diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index 2c96ce01c6328..459681ad6c40c 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -180,7 +180,7 @@ def test_iter_expanding_dataframe(df, expected, min_periods): df = DataFrame(df) expecteds = [DataFrame(values, index=index) for (values, index) in expected] - for expected, actual in zip(expecteds, df.expanding(min_periods)): + for expected, actual in zip(expecteds, df.expanding(min_periods), strict=False): tm.assert_frame_equal(actual, expected) @@ -199,7 +199,7 @@ def test_iter_expanding_series(ser, expected, min_periods): # GH 11704 expecteds = [Series(values, index=index) for (values, index) in expected] - for expected, actual in zip(expecteds, ser.expanding(min_periods)): + for expected, actual in zip(expecteds, ser.expanding(min_periods), strict=False): tm.assert_series_equal(actual, expected) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 18aafa0d7b71e..7a52b18260974 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -764,7 +764,9 @@ def test_iter_rolling_dataframe(df, expected, window, min_periods): df = DataFrame(df) expecteds = [DataFrame(values, index=index) for (values, index) in expected] - for expected, actual in zip(expecteds, df.rolling(window, min_periods=min_periods)): + for expected, actual in zip( + expecteds, df.rolling(window, min_periods=min_periods), strict=False + ): tm.assert_frame_equal(actual, expected) @@ -810,7 +812,7 @@ def test_iter_rolling_on_dataframe(expected, window): expecteds = [ DataFrame(values, index=df.loc[index, "C"]) for (values, index) in expected ] - for expected, actual in zip(expecteds, df.rolling(window, on="C")): + for expected, actual in zip(expecteds, df.rolling(window, on="C"), strict=False): tm.assert_frame_equal(actual, expected) @@ -819,7 +821,7 @@ def test_iter_rolling_on_dataframe_unordered(): df = DataFrame({"a": ["x", "y", "x"], "b": [0, 1, 2]}) results = list(df.groupby("a").rolling(2)) expecteds = [df.iloc[idx, [1]] for idx in [[0], [0, 2], [1]]] - for result, expected in zip(results, expecteds): + for result, expected in zip(results, expecteds, strict=False): tm.assert_frame_equal(result, expected) @@ -861,7 +863,7 @@ def test_iter_rolling_series(ser, expected, window, min_periods): expecteds = [Series(values, index=index) for (values, index) in expected] for expected, actual in zip( - expecteds, ser.rolling(window, min_periods=min_periods) + expecteds, ser.rolling(window, min_periods=min_periods), strict=False ): tm.assert_series_equal(actual, expected) @@ -909,10 +911,11 @@ def test_iter_rolling_datetime(expected, expected_index, window): ser = Series(range(5), index=date_range(start="2020-01-01", periods=5, freq="D")) expecteds = [ - Series(values, index=idx) for (values, idx) in zip(expected, expected_index) + Series(values, index=idx) + for (values, idx) in zip(expected, expected_index, strict=False) ] - for expected, actual in zip(expecteds, ser.rolling(window)): + for expected, actual in zip(expecteds, ser.rolling(window), strict=False): tm.assert_series_equal(actual, expected) diff --git a/pyproject.toml b/pyproject.toml index 094d0b44a6721..49bb49aab03c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -591,9 +591,6 @@ exclude = [ "pandas/tests/tseries/offsets/test_month.py" = ["B905"] "pandas/tests/tseries/offsets/test_offsets.py" = ["B905"] "pandas/tests/util/test_validate_kwargs.py" = ["B905"] -"pandas/tests/window/test_cython_aggregations.py" = ["B905"] -"pandas/tests/window/test_expanding.py" = ["B905"] -"pandas/tests/window/test_rolling.py" = ["B905"] "scripts/validate_unwanted_patterns.py" = ["B905"] [tool.ruff.lint.flake8-pytest-style] From a7be4e263746e4c88c6773f2b334752b73b5d04a Mon Sep 17 00:00:00 2001 From: Zorex Salvo Date: Tue, 28 Oct 2025 16:24:06 +0800 Subject: [PATCH 2/2] STY: Use strict=True for cases that need it --- pandas/tests/window/test_cython_aggregations.py | 2 +- pandas/tests/window/test_expanding.py | 2 +- pandas/tests/window/test_rolling.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/tests/window/test_cython_aggregations.py b/pandas/tests/window/test_cython_aggregations.py index f5f33d889da75..2e23618a3a201 100644 --- a/pandas/tests/window/test_cython_aggregations.py +++ b/pandas/tests/window/test_cython_aggregations.py @@ -62,7 +62,7 @@ def _get_rolling_aggregations(): ] ) # unzip to a list of 2 tuples, names and functions - unzipped = list(zip(*named_roll_aggs, strict=False)) + unzipped = list(zip(*named_roll_aggs, strict=True)) return {"ids": unzipped[0], "params": unzipped[1]} diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index 459681ad6c40c..ddcdf07beeb4c 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -199,7 +199,7 @@ def test_iter_expanding_series(ser, expected, min_periods): # GH 11704 expecteds = [Series(values, index=index) for (values, index) in expected] - for expected, actual in zip(expecteds, ser.expanding(min_periods), strict=False): + for expected, actual in zip(expecteds, ser.expanding(min_periods), strict=True): tm.assert_series_equal(actual, expected) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 7a52b18260974..3003b142edd3b 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -821,7 +821,7 @@ def test_iter_rolling_on_dataframe_unordered(): df = DataFrame({"a": ["x", "y", "x"], "b": [0, 1, 2]}) results = list(df.groupby("a").rolling(2)) expecteds = [df.iloc[idx, [1]] for idx in [[0], [0, 2], [1]]] - for result, expected in zip(results, expecteds, strict=False): + for result, expected in zip(results, expecteds, strict=True): tm.assert_frame_equal(result, expected) @@ -863,7 +863,7 @@ def test_iter_rolling_series(ser, expected, window, min_periods): expecteds = [Series(values, index=index) for (values, index) in expected] for expected, actual in zip( - expecteds, ser.rolling(window, min_periods=min_periods), strict=False + expecteds, ser.rolling(window, min_periods=min_periods), strict=True ): tm.assert_series_equal(actual, expected) @@ -912,10 +912,10 @@ def test_iter_rolling_datetime(expected, expected_index, window): expecteds = [ Series(values, index=idx) - for (values, idx) in zip(expected, expected_index, strict=False) + for (values, idx) in zip(expected, expected_index, strict=True) ] - for expected, actual in zip(expecteds, ser.rolling(window), strict=False): + for expected, actual in zip(expecteds, ser.rolling(window), strict=True): tm.assert_series_equal(actual, expected)