@@ -1521,8 +1521,8 @@ def test_isetitem_series(using_copy_on_write, dtype):
1521
1521
df .isetitem (0 , ser )
1522
1522
1523
1523
if using_copy_on_write :
1524
- # TODO(CoW) this can share memory
1525
- assert not np . shares_memory ( get_array ( df , "a" ), get_array ( ser ) )
1524
+ assert np . shares_memory ( get_array ( df , "a" ), get_array ( ser ))
1525
+ assert not df . _mgr . _has_no_reference ( 0 )
1526
1526
1527
1527
# mutating dataframe doesn't update series
1528
1528
df .loc [0 , "a" ] = 0
@@ -1538,6 +1538,23 @@ def test_isetitem_series(using_copy_on_write, dtype):
1538
1538
tm .assert_frame_equal (df , expected )
1539
1539
1540
1540
1541
+ def test_isetitem_frame (using_copy_on_write ):
1542
+ df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : 1 , "c" : 2 })
1543
+ rhs = DataFrame ({"a" : [4 , 5 , 6 ], "b" : 2 })
1544
+ df .isetitem ([0 , 1 ], rhs )
1545
+ if using_copy_on_write :
1546
+ assert np .shares_memory (get_array (df , "a" ), get_array (rhs , "a" ))
1547
+ assert np .shares_memory (get_array (df , "b" ), get_array (rhs , "b" ))
1548
+ assert not df ._mgr ._has_no_reference (0 )
1549
+ else :
1550
+ assert not np .shares_memory (get_array (df , "a" ), get_array (rhs , "a" ))
1551
+ assert not np .shares_memory (get_array (df , "b" ), get_array (rhs , "b" ))
1552
+ expected = df .copy ()
1553
+ rhs .iloc [0 , 0 ] = 100
1554
+ rhs .iloc [0 , 1 ] = 100
1555
+ tm .assert_frame_equal (df , expected )
1556
+
1557
+
1541
1558
@pytest .mark .parametrize ("key" , ["a" , ["a" ]])
1542
1559
def test_get (using_copy_on_write , key ):
1543
1560
df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]})
0 commit comments