Skip to content

Commit e27bded

Browse files
authored
TST: CoW with df.isetitem() (#50692)
1 parent 2d6d744 commit e27bded

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/copy_view/test_methods.py

+22
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,25 @@ def test_squeeze(using_copy_on_write):
759759
# Without CoW the original will be modified
760760
assert np.shares_memory(series.values, get_array(df, "a"))
761761
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

Comments
 (0)