Skip to content

Commit db52915

Browse files
lithomas1phofl
authored andcommitted
TST: CoW with df.isetitem() (pandas-dev#50692)
1 parent c829164 commit db52915

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
@@ -774,3 +774,25 @@ def test_putmask(using_copy_on_write):
774774
# Without CoW the original will be modified
775775
assert np.shares_memory(get_array(view, "a"), get_array(df, "a"))
776776
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

Comments
 (0)