Skip to content

Commit 29718c3

Browse files
ganevgvjreback
authored andcommitted
TST: add tests for Series/DF logical operations nan propagation (#29531)
1 parent beb23bd commit 29718c3

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

pandas/tests/frame/test_operators.py

+36
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,42 @@ def test_logical_with_nas(self):
218218
expected = Series([True, True])
219219
tm.assert_series_equal(result, expected)
220220

221+
@pytest.mark.parametrize(
222+
"left, right, op, expected",
223+
[
224+
(
225+
[True, False, np.nan],
226+
[True, False, True],
227+
operator.and_,
228+
[True, False, False],
229+
),
230+
(
231+
[True, False, True],
232+
[True, False, np.nan],
233+
operator.and_,
234+
[True, False, False],
235+
),
236+
(
237+
[True, False, np.nan],
238+
[True, False, True],
239+
operator.or_,
240+
[True, False, False],
241+
),
242+
(
243+
[True, False, True],
244+
[True, False, np.nan],
245+
operator.or_,
246+
[True, False, True],
247+
),
248+
],
249+
)
250+
def test_logical_operators_nans(self, left, right, op, expected):
251+
# GH 13896
252+
result = op(DataFrame(left), DataFrame(right))
253+
expected = DataFrame(expected)
254+
255+
tm.assert_frame_equal(result, expected)
256+
221257

222258
class TestDataFrameOperators:
223259
@pytest.mark.parametrize(

pandas/tests/series/test_operators.py

+36
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,42 @@ def test_logical_operators_bool_dtype_with_empty(self):
4343
expected = s_tft
4444
tm.assert_series_equal(res, expected)
4545

46+
@pytest.mark.parametrize(
47+
"left, right, op, expected",
48+
[
49+
(
50+
[True, False, np.nan],
51+
[True, False, True],
52+
operator.and_,
53+
[True, False, False],
54+
),
55+
(
56+
[True, False, True],
57+
[True, False, np.nan],
58+
operator.and_,
59+
[True, False, False],
60+
),
61+
(
62+
[True, False, np.nan],
63+
[True, False, True],
64+
operator.or_,
65+
[True, False, False],
66+
),
67+
(
68+
[True, False, True],
69+
[True, False, np.nan],
70+
operator.or_,
71+
[True, False, True],
72+
),
73+
],
74+
)
75+
def test_logical_operators_nans(self, left, right, op, expected):
76+
# GH 13896
77+
result = op(Series(left), Series(right))
78+
expected = Series(expected)
79+
80+
tm.assert_series_equal(result, expected)
81+
4682
def test_logical_operators_int_dtype_with_int_dtype(self):
4783
# GH#9016: support bitwise op for integer types
4884

0 commit comments

Comments
 (0)