Skip to content

Commit d9bcbcf

Browse files
majiayu000claude
andcommitted
Address review feedback: simplify logical ops tests
- Remove inline comments from parametrized test cases - Change type annotation from list[object] to list[bool] - Remove test_col_logical_ops_combined and add .loc testing to the main parametrized test function 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 640dad1 commit d9bcbcf

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

pandas/tests/test_col.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ def mean(self):
102102
@pytest.mark.parametrize(
103103
("expr", "expected_values", "expected_str"),
104104
[
105-
# __and__ and __rand__
106-
# a = [True, False, True, False], b = [False, True, True, True]
107-
# a & b = [False, False, True, False]
108105
(
109106
pd.col("a") & pd.col("b"),
110107
[False, False, True, False],
@@ -115,7 +112,6 @@ def mean(self):
115112
[True, False, True, False],
116113
"(col('a') & True)",
117114
),
118-
# __or__ and __ror__
119115
(
120116
pd.col("a") | pd.col("b"),
121117
[True, True, True, True],
@@ -126,8 +122,6 @@ def mean(self):
126122
[True, False, True, False],
127123
"(col('a') | False)",
128124
),
129-
# __xor__ and __rxor__
130-
# a ^ b = [True, True, False, True]
131125
(
132126
pd.col("a") ^ pd.col("b"),
133127
[True, True, False, True],
@@ -138,7 +132,6 @@ def mean(self):
138132
[False, True, False, True],
139133
"(col('a') ^ True)",
140134
),
141-
# __invert__
142135
(
143136
~pd.col("a"),
144137
[False, True, False, True],
@@ -147,7 +140,7 @@ def mean(self):
147140
],
148141
)
149142
def test_col_logical_ops(
150-
expr: Expression, expected_values: list[object], expected_str: str
143+
expr: Expression, expected_values: list[bool], expected_str: str
151144
) -> None:
152145
df = pd.DataFrame({"a": [True, False, True, False], "b": [False, True, True, True]})
153146
result = df.assign(c=expr)
@@ -161,29 +154,7 @@ def test_col_logical_ops(
161154
tm.assert_frame_equal(result, expected)
162155
assert str(expr) == expected_str
163156

164-
165-
def test_col_logical_ops_combined() -> None:
166-
"""Test combining multiple logical operators like in DataFrame.loc[]."""
167-
df = pd.DataFrame(
168-
{
169-
"x": [1, 2, 3, 4, 5],
170-
"y": [10, 20, 30, 40, 50],
171-
}
172-
)
173-
# Test combining conditions with & operator
174-
expr = (pd.col("x") > 2) & (pd.col("y") < 45)
175-
result = df.loc[expr]
176-
expected = df.loc[(df["x"] > 2) & (df["y"] < 45)]
177-
tm.assert_frame_equal(result, expected)
178-
179-
# Test combining conditions with | operator
180-
expr = (pd.col("x") == 1) | (pd.col("x") == 5)
181-
result = df.loc[expr]
182-
expected = df.loc[(df["x"] == 1) | (df["x"] == 5)]
183-
tm.assert_frame_equal(result, expected)
184-
185-
# Test negation with ~
186-
expr = ~(pd.col("x") > 3)
157+
# Test that the expression works with .loc
187158
result = df.loc[expr]
188-
expected = df.loc[~(df["x"] > 3)]
159+
expected = df[expected_values]
189160
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)