@@ -774,3 +774,25 @@ def test_putmask(using_copy_on_write):
774
774
# Without CoW the original will be modified
775
775
assert np .shares_memory (get_array (view , "a" ), get_array (df , "a" ))
776
776
assert view .iloc [0 , 0 ] == 5
777
+
778
+
779
+ def test_isetitem (using_copy_on_write ):
780
+ df = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ], "c" : [7 , 8 , 9 ]})
781
+ df_orig = df .copy ()
782
+ df2 = df .copy (deep = None ) # Trigger a CoW
783
+ df2 .isetitem (1 , np .array ([- 1 , - 2 , - 3 ])) # This is inplace
784
+
785
+ if using_copy_on_write :
786
+ assert np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
787
+ assert np .shares_memory (get_array (df , "a" ), get_array (df2 , "a" ))
788
+ else :
789
+ assert not np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
790
+ assert not np .shares_memory (get_array (df , "a" ), get_array (df2 , "a" ))
791
+
792
+ df2 .loc [0 , "a" ] = 0
793
+ tm .assert_frame_equal (df , df_orig ) # Original is unchanged
794
+
795
+ if using_copy_on_write :
796
+ assert np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
797
+ else :
798
+ assert not np .shares_memory (get_array (df , "c" ), get_array (df2 , "c" ))
0 commit comments