Skip to content

Commit 747e046

Browse files
committed
added tests for inplace mutation
1 parent 36b171b commit 747e046

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pandas/tests/arrays/test_boolean.py

+39
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ def test_kleene_or(self):
408408
result = b | a
409409
tm.assert_extension_array_equal(result, expected)
410410

411+
# ensure we haven't mutated anything inplace
412+
tm.assert_extension_array_equal(
413+
a, pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
414+
)
415+
tm.assert_extension_array_equal(
416+
b, pd.array([True, False, None] * 3, dtype="boolean")
417+
)
418+
411419
@pytest.mark.parametrize(
412420
"other, expected",
413421
[
@@ -426,6 +434,11 @@ def test_kleene_or_scalar(self, other, expected):
426434
result = other | a
427435
tm.assert_extension_array_equal(result, expected)
428436

437+
# ensure we haven't mutated anything inplace
438+
tm.assert_extension_array_equal(
439+
a, pd.array([True, False, None], dtype="boolean")
440+
)
441+
429442
def test_kleene_and(self):
430443
# A clear test of behavior.
431444
a = pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
@@ -439,6 +452,14 @@ def test_kleene_and(self):
439452
result = b & a
440453
tm.assert_extension_array_equal(result, expected)
441454

455+
# ensure we haven't mutated anything inplace
456+
tm.assert_extension_array_equal(
457+
a, pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
458+
)
459+
tm.assert_extension_array_equal(
460+
b, pd.array([True, False, None] * 3, dtype="boolean")
461+
)
462+
442463
@pytest.mark.parametrize(
443464
"other, expected",
444465
[
@@ -456,6 +477,11 @@ def test_kleene_and_scalar(self, other, expected):
456477
result = other & a
457478
tm.assert_extension_array_equal(result, expected)
458479

480+
# ensure we haven't mutated anything inplace
481+
tm.assert_extension_array_equal(
482+
a, pd.array([True, False, None], dtype="boolean")
483+
)
484+
459485
def test_kleene_xor(self):
460486
a = pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
461487
b = pd.array([True, False, None] * 3, dtype="boolean")
@@ -468,6 +494,14 @@ def test_kleene_xor(self):
468494
result = b ^ a
469495
tm.assert_extension_array_equal(result, expected)
470496

497+
# ensure we haven't mutated anything inplace
498+
tm.assert_extension_array_equal(
499+
a, pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
500+
)
501+
tm.assert_extension_array_equal(
502+
b, pd.array([True, False, None] * 3, dtype="boolean")
503+
)
504+
471505
@pytest.mark.parametrize(
472506
"other, expected",
473507
[
@@ -485,6 +519,11 @@ def test_kleene_xor_scalar(self, other, expected):
485519
result = other ^ a
486520
tm.assert_extension_array_equal(result, expected)
487521

522+
# ensure we haven't mutated anything inplace
523+
tm.assert_extension_array_equal(
524+
a, pd.array([True, False, None], dtype="boolean")
525+
)
526+
488527

489528
class TestComparisonOps(BaseOpsUtil):
490529
def _compare_other(self, data, op_name, other):

0 commit comments

Comments
 (0)