From 86fe79bab502e4f2dc5327801fa53f05dc112542 Mon Sep 17 00:00:00 2001 From: Ghazi-raad Date: Fri, 28 Nov 2025 18:58:45 +0000 Subject: [PATCH] STY: Add strict=True to zip() calls in pandas/tests/reshape This commit enforces Ruff rule B905 (zip-without-explicit-strict) for the pandas/tests/reshape directory. All zip() calls now explicitly specify strict=True to ensure equal-length iterator assumptions are validated at runtime. Related to issue #62434 --- pandas/tests/reshape/concat/test_concat.py | 2 +- pandas/tests/reshape/concat/test_index.py | 4 ++-- pandas/tests/reshape/test_melt.py | 6 +++--- pandas/tests/reshape/test_qcut.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 7d0e534cb7689..e38dbfe2def43 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -707,7 +707,7 @@ def test_concat_repeated_keys(keys, integrity): # GH: 20816 series_list = [Series({"a": 1}), Series({"b": 2}), Series({"c": 3})] result = concat(series_list, keys=keys, verify_integrity=integrity) - tuples = list(zip(keys, ["a", "b", "c"])) + tuples = list(zip(keys, ["a", "b", "c"], strict=True)) expected = Series([1, 2, 3], index=MultiIndex.from_tuples(tuples)) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/reshape/concat/test_index.py b/pandas/tests/reshape/concat/test_index.py index ace0776ae6143..62a8910a83c8e 100644 --- a/pandas/tests/reshape/concat/test_index.py +++ b/pandas/tests/reshape/concat/test_index.py @@ -60,7 +60,7 @@ def test_concat_same_index_names(self, name_in1, name_in2, name_in3, name_out): Index(["c", "d", "e"], name=name_in3), ] frames = [ - DataFrame({c: [0, 1, 2]}, index=i) for i, c in zip(indices, ["x", "y", "z"]) + DataFrame({c: [0, 1, 2]}, index=i) for i, c in zip(indices, ["x", "y", "z"], strict=True) ] result = concat(frames, axis=1) @@ -218,7 +218,7 @@ def test_concat_multiindex_with_none_in_index_names(self): level2 = [1] * 5 + [2] * 2 level1 = [1] * 7 no_name = list(range(5)) + list(range(2)) - tuples = list(zip(level2, level1, no_name)) + tuples = list(zip(level2, level1, no_name, strict=True)) index = MultiIndex.from_tuples(tuples, names=["level2", "level1", None]) expected = DataFrame({"col": no_name}, index=index, dtype=np.int32) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/reshape/test_melt.py b/pandas/tests/reshape/test_melt.py index fba9c28282e94..d347d42ee6192 100644 --- a/pandas/tests/reshape/test_melt.py +++ b/pandas/tests/reshape/test_melt.py @@ -801,7 +801,7 @@ def test_simple(self): "A1980": {0: "d", 1: "e", 2: "f"}, "B1970": {0: 2.5, 1: 1.2, 2: 0.7}, "B1980": {0: 3.2, 1: 1.3, 2: 0.1}, - "X": dict(zip(range(3), x)), + "X": dict(zip(range(3), x, strict=True)), } ) df["id"] = df.index @@ -837,7 +837,7 @@ def test_separating_character(self): "A.1980": {0: "d", 1: "e", 2: "f"}, "B.1970": {0: 2.5, 1: 1.2, 2: 0.7}, "B.1980": {0: 3.2, 1: 1.3, 2: 0.1}, - "X": dict(zip(range(3), x)), + "X": dict(zip(range(3), x, strict=True)), } ) df["id"] = df.index @@ -861,7 +861,7 @@ def test_escapable_characters(self): "A(quarterly)1980": {0: "d", 1: "e", 2: "f"}, "B(quarterly)1970": {0: 2.5, 1: 1.2, 2: 0.7}, "B(quarterly)1980": {0: 3.2, 1: 1.3, 2: 0.1}, - "X": dict(zip(range(3), x)), + "X": dict(zip(range(3), x, strict=True)), } ) df["id"] = df.index diff --git a/pandas/tests/reshape/test_qcut.py b/pandas/tests/reshape/test_qcut.py index b6d45aeab8a7b..9b6b709b80d2c 100644 --- a/pandas/tests/reshape/test_qcut.py +++ b/pandas/tests/reshape/test_qcut.py @@ -304,5 +304,5 @@ def test_qcut_contains(scale, q, precision): arr = (scale * np.arange(q + 1)).round(precision) result = qcut(arr, q, precision=precision) - for value, bucket in zip(arr, result): + for value, bucket in zip(arr, result, strict=True): assert value in bucket