Skip to content

Commit 49851bb

Browse files
authored
TST / CoW: Add test for mask (#53745)
1 parent 7133cf8 commit 49851bb

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

pandas/tests/copy_view/test_methods.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -1428,11 +1428,18 @@ def test_putmask_dont_copy_some_blocks(using_copy_on_write, val, exp):
14281428

14291429

14301430
@pytest.mark.parametrize("dtype", ["int64", "Int64"])
1431-
def test_where_noop(using_copy_on_write, dtype):
1431+
@pytest.mark.parametrize(
1432+
"func",
1433+
[
1434+
lambda ser: ser.where(ser > 0, 10),
1435+
lambda ser: ser.mask(ser <= 0, 10),
1436+
],
1437+
)
1438+
def test_where_mask_noop(using_copy_on_write, dtype, func):
14321439
ser = Series([1, 2, 3], dtype=dtype)
14331440
ser_orig = ser.copy()
14341441

1435-
result = ser.where(ser > 0, 10)
1442+
result = func(ser)
14361443

14371444
if using_copy_on_write:
14381445
assert np.shares_memory(get_array(ser), get_array(result))
@@ -1446,22 +1453,36 @@ def test_where_noop(using_copy_on_write, dtype):
14461453

14471454

14481455
@pytest.mark.parametrize("dtype", ["int64", "Int64"])
1449-
def test_where(using_copy_on_write, dtype):
1456+
@pytest.mark.parametrize(
1457+
"func",
1458+
[
1459+
lambda ser: ser.where(ser < 0, 10),
1460+
lambda ser: ser.mask(ser >= 0, 10),
1461+
],
1462+
)
1463+
def test_where_mask(using_copy_on_write, dtype, func):
14501464
ser = Series([1, 2, 3], dtype=dtype)
14511465
ser_orig = ser.copy()
14521466

1453-
result = ser.where(ser < 0, 10)
1467+
result = func(ser)
14541468

14551469
assert not np.shares_memory(get_array(ser), get_array(result))
14561470
tm.assert_series_equal(ser, ser_orig)
14571471

14581472

14591473
@pytest.mark.parametrize("dtype, val", [("int64", 10.5), ("Int64", 10)])
1460-
def test_where_noop_on_single_column(using_copy_on_write, dtype, val):
1474+
@pytest.mark.parametrize(
1475+
"func",
1476+
[
1477+
lambda df, val: df.where(df < 0, val),
1478+
lambda df, val: df.mask(df >= 0, val),
1479+
],
1480+
)
1481+
def test_where_mask_noop_on_single_column(using_copy_on_write, dtype, val, func):
14611482
df = DataFrame({"a": [1, 2, 3], "b": [-4, -5, -6]}, dtype=dtype)
14621483
df_orig = df.copy()
14631484

1464-
result = df.where(df < 0, val)
1485+
result = func(df, val)
14651486

14661487
if using_copy_on_write:
14671488
assert np.shares_memory(get_array(df, "b"), get_array(result, "b"))

0 commit comments

Comments
 (0)