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