@@ -1428,11 +1428,18 @@ def test_putmask_dont_copy_some_blocks(using_copy_on_write, val, exp):
1428
1428
1429
1429
1430
1430
@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 ):
1432
1439
ser = Series ([1 , 2 , 3 ], dtype = dtype )
1433
1440
ser_orig = ser .copy ()
1434
1441
1435
- result = ser . where (ser > 0 , 10 )
1442
+ result = func (ser )
1436
1443
1437
1444
if using_copy_on_write :
1438
1445
assert np .shares_memory (get_array (ser ), get_array (result ))
@@ -1446,22 +1453,36 @@ def test_where_noop(using_copy_on_write, dtype):
1446
1453
1447
1454
1448
1455
@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 ):
1450
1464
ser = Series ([1 , 2 , 3 ], dtype = dtype )
1451
1465
ser_orig = ser .copy ()
1452
1466
1453
- result = ser . where (ser < 0 , 10 )
1467
+ result = func (ser )
1454
1468
1455
1469
assert not np .shares_memory (get_array (ser ), get_array (result ))
1456
1470
tm .assert_series_equal (ser , ser_orig )
1457
1471
1458
1472
1459
1473
@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 ):
1461
1482
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [- 4 , - 5 , - 6 ]}, dtype = dtype )
1462
1483
df_orig = df .copy ()
1463
1484
1464
- result = df . where (df < 0 , val )
1485
+ result = func (df , val )
1465
1486
1466
1487
if using_copy_on_write :
1467
1488
assert np .shares_memory (get_array (df , "b" ), get_array (result , "b" ))
0 commit comments