Skip to content

Commit cc07895

Browse files
authored
Remove Copy-on-Write warning mode from tests (#57237)
1 parent b3ea5f4 commit cc07895

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+317
-788
lines changed

pandas/conftest.py

-8
Original file line numberDiff line numberDiff line change
@@ -1966,14 +1966,6 @@ def using_copy_on_write() -> bool:
19661966
return True
19671967

19681968

1969-
@pytest.fixture
1970-
def warn_copy_on_write() -> bool:
1971-
"""
1972-
Fixture to check if Copy-on-Write is in warning mode.
1973-
"""
1974-
return False
1975-
1976-
19771969
@pytest.fixture
19781970
def using_infer_string() -> bool:
19791971
"""

pandas/tests/apply/test_frame_apply.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ def test_apply_dtype(col):
14871487
tm.assert_series_equal(result, expected)
14881488

14891489

1490-
def test_apply_mutating(using_copy_on_write, warn_copy_on_write):
1490+
def test_apply_mutating(using_copy_on_write):
14911491
# GH#35462 case where applied func pins a new BlockManager to a row
14921492
df = DataFrame({"a": range(100), "b": range(100, 200)})
14931493
df_orig = df.copy()
@@ -1501,8 +1501,7 @@ def func(row):
15011501
expected = df.copy()
15021502
expected["a"] += 1
15031503

1504-
with tm.assert_cow_warning(warn_copy_on_write):
1505-
result = df.apply(func, axis=1)
1504+
result = df.apply(func, axis=1)
15061505

15071506
tm.assert_frame_equal(result, expected)
15081507
if using_copy_on_write:

pandas/tests/computation/test_eval.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ def test_assignment_not_inplace(self):
12901290
expected["c"] = expected["a"] + expected["b"]
12911291
tm.assert_frame_equal(df, expected)
12921292

1293-
def test_multi_line_expression(self, warn_copy_on_write):
1293+
def test_multi_line_expression(self):
12941294
# GH 11149
12951295
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
12961296
expected = df.copy()
@@ -1964,15 +1964,14 @@ def test_eval_no_support_column_name(request, column):
19641964
tm.assert_frame_equal(result, expected)
19651965

19661966

1967-
def test_set_inplace(using_copy_on_write, warn_copy_on_write):
1967+
def test_set_inplace(using_copy_on_write):
19681968
# https://github.com/pandas-dev/pandas/issues/47449
19691969
# Ensure we don't only update the DataFrame inplace, but also the actual
19701970
# column values, such that references to this column also get updated
19711971
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
19721972
result_view = df[:]
19731973
ser = df["A"]
1974-
with tm.assert_cow_warning(warn_copy_on_write):
1975-
df.eval("A = B + C", inplace=True)
1974+
df.eval("A = B + C", inplace=True)
19761975
expected = DataFrame({"A": [11, 13, 15], "B": [4, 5, 6], "C": [7, 8, 9]})
19771976
tm.assert_frame_equal(df, expected)
19781977
if not using_copy_on_write:

pandas/tests/copy_view/index/test_index.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ def index_view(index_data):
1919
return idx, view
2020

2121

22-
def test_set_index_update_column(using_copy_on_write, warn_copy_on_write):
22+
def test_set_index_update_column(using_copy_on_write):
2323
df = DataFrame({"a": [1, 2], "b": 1})
2424
df = df.set_index("a", drop=False)
2525
expected = df.index.copy(deep=True)
26-
with tm.assert_cow_warning(warn_copy_on_write):
27-
df.iloc[0, 0] = 100
26+
df.iloc[0, 0] = 100
2827
if using_copy_on_write:
2928
tm.assert_index_equal(df.index, expected)
3029
else:
@@ -40,53 +39,49 @@ def test_set_index_drop_update_column(using_copy_on_write):
4039
tm.assert_index_equal(df.index, expected)
4140

4241

43-
def test_set_index_series(using_copy_on_write, warn_copy_on_write):
42+
def test_set_index_series(using_copy_on_write):
4443
df = DataFrame({"a": [1, 2], "b": 1.5})
4544
ser = Series([10, 11])
4645
df = df.set_index(ser)
4746
expected = df.index.copy(deep=True)
48-
with tm.assert_cow_warning(warn_copy_on_write):
49-
ser.iloc[0] = 100
47+
ser.iloc[0] = 100
5048
if using_copy_on_write:
5149
tm.assert_index_equal(df.index, expected)
5250
else:
5351
tm.assert_index_equal(df.index, Index([100, 11]))
5452

5553

56-
def test_assign_index_as_series(using_copy_on_write, warn_copy_on_write):
54+
def test_assign_index_as_series(using_copy_on_write):
5755
df = DataFrame({"a": [1, 2], "b": 1.5})
5856
ser = Series([10, 11])
5957
df.index = ser
6058
expected = df.index.copy(deep=True)
61-
with tm.assert_cow_warning(warn_copy_on_write):
62-
ser.iloc[0] = 100
59+
ser.iloc[0] = 100
6360
if using_copy_on_write:
6461
tm.assert_index_equal(df.index, expected)
6562
else:
6663
tm.assert_index_equal(df.index, Index([100, 11]))
6764

6865

69-
def test_assign_index_as_index(using_copy_on_write, warn_copy_on_write):
66+
def test_assign_index_as_index(using_copy_on_write):
7067
df = DataFrame({"a": [1, 2], "b": 1.5})
7168
ser = Series([10, 11])
7269
rhs_index = Index(ser)
7370
df.index = rhs_index
7471
rhs_index = None # overwrite to clear reference
7572
expected = df.index.copy(deep=True)
76-
with tm.assert_cow_warning(warn_copy_on_write):
77-
ser.iloc[0] = 100
73+
ser.iloc[0] = 100
7874
if using_copy_on_write:
7975
tm.assert_index_equal(df.index, expected)
8076
else:
8177
tm.assert_index_equal(df.index, Index([100, 11]))
8278

8379

84-
def test_index_from_series(using_copy_on_write, warn_copy_on_write):
80+
def test_index_from_series(using_copy_on_write):
8581
ser = Series([1, 2])
8682
idx = Index(ser)
8783
expected = idx.copy(deep=True)
88-
with tm.assert_cow_warning(warn_copy_on_write):
89-
ser.iloc[0] = 100
84+
ser.iloc[0] = 100
9085
if using_copy_on_write:
9186
tm.assert_index_equal(idx, expected)
9287
else:
@@ -101,13 +96,12 @@ def test_index_from_series_copy(using_copy_on_write):
10196
assert np.shares_memory(get_array(ser), arr)
10297

10398

104-
def test_index_from_index(using_copy_on_write, warn_copy_on_write):
99+
def test_index_from_index(using_copy_on_write):
105100
ser = Series([1, 2])
106101
idx = Index(ser)
107102
idx = Index(idx)
108103
expected = idx.copy(deep=True)
109-
with tm.assert_cow_warning(warn_copy_on_write):
110-
ser.iloc[0] = 100
104+
ser.iloc[0] = 100
111105
if using_copy_on_write:
112106
tm.assert_index_equal(idx, expected)
113107
else:

pandas/tests/copy_view/test_chained_assignment_deprecation.py

+1-108
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import PY311
54
from pandas.errors import (
65
ChainedAssignmentError,
76
SettingWithCopyWarning,
@@ -33,117 +32,11 @@ def test_methods_iloc_warn(using_copy_on_write):
3332
df.iloc[:, 0].bfill(inplace=True)
3433

3534

36-
@pytest.mark.parametrize(
37-
"func, args",
38-
[
39-
("replace", (4, 5)),
40-
("fillna", (1,)),
41-
("interpolate", ()),
42-
("bfill", ()),
43-
("ffill", ()),
44-
],
45-
)
46-
def test_methods_iloc_getitem_item_cache(
47-
func, args, using_copy_on_write, warn_copy_on_write
48-
):
49-
# ensure we don't incorrectly raise chained assignment warning because
50-
# of the item cache / iloc not setting the item cache
51-
df_orig = DataFrame({"a": [1, 2, 3], "b": 1})
52-
53-
df = df_orig.copy()
54-
ser = df.iloc[:, 0]
55-
getattr(ser, func)(*args, inplace=True)
56-
57-
# parent that holds item_cache is dead, so don't increase ref count
58-
df = df_orig.copy()
59-
ser = df.copy()["a"]
60-
getattr(ser, func)(*args, inplace=True)
61-
62-
df = df_orig.copy()
63-
df["a"] # populate the item_cache
64-
ser = df.iloc[:, 0] # iloc creates a new object
65-
getattr(ser, func)(*args, inplace=True)
66-
67-
df = df_orig.copy()
68-
df["a"] # populate the item_cache
69-
ser = df["a"]
70-
getattr(ser, func)(*args, inplace=True)
71-
72-
df = df_orig.copy()
73-
df["a"] # populate the item_cache
74-
# TODO(CoW-warn) because of the usage of *args, this doesn't warn on Py3.11+
75-
if using_copy_on_write:
76-
with tm.raises_chained_assignment_error(not PY311):
77-
getattr(df["a"], func)(*args, inplace=True)
78-
else:
79-
with tm.assert_cow_warning(not PY311, match="A value"):
80-
getattr(df["a"], func)(*args, inplace=True)
81-
82-
df = df_orig.copy()
83-
ser = df["a"] # populate the item_cache and keep ref
84-
if using_copy_on_write:
85-
with tm.raises_chained_assignment_error(not PY311):
86-
getattr(df["a"], func)(*args, inplace=True)
87-
else:
88-
# ideally also warns on the default mode, but the ser' _cacher
89-
# messes up the refcount + even in warning mode this doesn't trigger
90-
# the warning of Py3.1+ (see above)
91-
with tm.assert_cow_warning(warn_copy_on_write and not PY311, match="A value"):
92-
getattr(df["a"], func)(*args, inplace=True)
93-
94-
95-
def test_methods_iloc_getitem_item_cache_fillna(
96-
using_copy_on_write, warn_copy_on_write
97-
):
98-
# ensure we don't incorrectly raise chained assignment warning because
99-
# of the item cache / iloc not setting the item cache
100-
df_orig = DataFrame({"a": [1, 2, 3], "b": 1})
101-
102-
df = df_orig.copy()
103-
ser = df.iloc[:, 0]
104-
ser.fillna(1, inplace=True)
105-
106-
# parent that holds item_cache is dead, so don't increase ref count
107-
df = df_orig.copy()
108-
ser = df.copy()["a"]
109-
ser.fillna(1, inplace=True)
110-
111-
df = df_orig.copy()
112-
df["a"] # populate the item_cache
113-
ser = df.iloc[:, 0] # iloc creates a new object
114-
ser.fillna(1, inplace=True)
115-
116-
df = df_orig.copy()
117-
df["a"] # populate the item_cache
118-
ser = df["a"]
119-
ser.fillna(1, inplace=True)
120-
121-
df = df_orig.copy()
122-
df["a"] # populate the item_cache
123-
if using_copy_on_write:
124-
with tm.raises_chained_assignment_error():
125-
df["a"].fillna(1, inplace=True)
126-
else:
127-
with tm.assert_cow_warning(match="A value"):
128-
df["a"].fillna(1, inplace=True)
129-
130-
df = df_orig.copy()
131-
ser = df["a"] # populate the item_cache and keep ref
132-
if using_copy_on_write:
133-
with tm.raises_chained_assignment_error():
134-
df["a"].fillna(1, inplace=True)
135-
else:
136-
# TODO(CoW-warn) ideally also warns on the default mode, but the ser' _cacher
137-
# messes up the refcount
138-
with tm.assert_cow_warning(warn_copy_on_write, match="A value"):
139-
df["a"].fillna(1, inplace=True)
140-
141-
14235
# TODO(CoW-warn) expand the cases
14336
@pytest.mark.parametrize(
14437
"indexer", [0, [0, 1], slice(0, 2), np.array([True, False, True])]
14538
)
146-
def test_series_setitem(indexer, using_copy_on_write, warn_copy_on_write):
39+
def test_series_setitem(indexer, using_copy_on_write):
14740
# ensure we only get a single warning for those typical cases of chained
14841
# assignment
14942
df = DataFrame({"a": [1, 2, 3], "b": 1})

pandas/tests/copy_view/test_clip.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
from pandas.tests.copy_view.util import get_array
99

1010

11-
def test_clip_inplace_reference(using_copy_on_write, warn_copy_on_write):
11+
def test_clip_inplace_reference(using_copy_on_write):
1212
df = DataFrame({"a": [1.5, 2, 3]})
1313
df_copy = df.copy()
1414
arr_a = get_array(df, "a")
1515
view = df[:]
16-
if warn_copy_on_write:
17-
with tm.assert_cow_warning():
18-
df.clip(lower=2, inplace=True)
19-
else:
20-
df.clip(lower=2, inplace=True)
16+
df.clip(lower=2, inplace=True)
2117

2218
if using_copy_on_write:
2319
assert not np.shares_memory(get_array(df, "a"), arr_a)

0 commit comments

Comments
 (0)