@@ -759,3 +759,25 @@ def test_squeeze(using_copy_on_write):
759
759
# Without CoW the original will be modified
760
760
assert np .shares_memory (series .values , get_array (df , "a" ))
761
761
assert df .loc [0 , "a" ] == 0
762
+
763
+
764
+ def test_isetitem (using_copy_on_write ):
765
+ df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ], "c" : [7 , 8 , 9 ]})
766
+ df_orig = df .copy ()
767
+ df2 = df .copy (deep = None ) # Trigger a CoW
768
+ df2 .isetitem (1 , np .array ([- 1 , - 2 , - 3 ])) # This is inplace
769
+
770
+ if using_copy_on_write :
771
+ assert np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
772
+ assert np .shares_memory (get_array (df , "a" ), get_array (df2 , "a" ))
773
+ else :
774
+ assert not np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
775
+ assert not np .shares_memory (get_array (df , "a" ), get_array (df2 , "a" ))
776
+
777
+ df2 .loc [0 , "a" ] = 0
778
+ tm .assert_frame_equal (df , df_orig ) # Original is unchanged
779
+
780
+ if using_copy_on_write :
781
+ assert np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
782
+ else :
783
+ assert not np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
0 commit comments