Skip to content

Commit 0fb84ae

Browse files
authored
TST: clip inplace doesn't modify views with CoW (#51402)
1 parent 047acde commit 0fb84ae

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/copy_view/test_clip.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import numpy as np
2+
3+
from pandas import DataFrame
4+
import pandas._testing as tm
5+
from pandas.tests.copy_view.util import get_array
6+
7+
8+
def test_clip_inplace_reference(using_copy_on_write):
9+
df = DataFrame({"a": [1.5, 2, 3]})
10+
df_copy = df.copy()
11+
arr_a = get_array(df, "a")
12+
view = df[:]
13+
df.clip(lower=2, inplace=True)
14+
15+
# Clip not actually inplace right now but could be
16+
assert not np.shares_memory(get_array(df, "a"), arr_a)
17+
18+
if using_copy_on_write:
19+
assert df._mgr._has_no_reference(0)
20+
assert view._mgr._has_no_reference(0)
21+
tm.assert_frame_equal(df_copy, view)

0 commit comments

Comments
 (0)