Skip to content

Commit 41eafa4

Browse files
phofljorisvandenbossche
authored andcommitted
ENH: Add test for asfreq CoW when doing noop (pandas-dev#50916)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 94b4d23 commit 41eafa4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/copy_view/test_methods.py

+20
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,26 @@ def test_putmask(using_copy_on_write):
11171117
assert view.iloc[0, 0] == 5
11181118

11191119

1120+
def test_asfreq_noop(using_copy_on_write):
1121+
df = DataFrame(
1122+
{"a": [0.0, None, 2.0, 3.0]},
1123+
index=date_range("1/1/2000", periods=4, freq="T"),
1124+
)
1125+
df_orig = df.copy()
1126+
df2 = df.asfreq(freq="T")
1127+
1128+
if using_copy_on_write:
1129+
assert np.shares_memory(get_array(df2, "a"), get_array(df, "a"))
1130+
else:
1131+
assert not np.shares_memory(get_array(df2, "a"), get_array(df, "a"))
1132+
1133+
# mutating df2 triggers a copy-on-write for that column / block
1134+
df2.iloc[0, 0] = 0
1135+
1136+
assert not np.shares_memory(get_array(df2, "a"), get_array(df, "a"))
1137+
tm.assert_frame_equal(df, df_orig)
1138+
1139+
11201140
def test_isetitem(using_copy_on_write):
11211141
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
11221142
df_orig = df.copy()

0 commit comments

Comments
 (0)