Skip to content

Commit 6669aee

Browse files
authored
CoW: Remove false positive warnings for inplace operators (#56242)
1 parent ae76ad4 commit 6669aee

File tree

5 files changed

+5
-16
lines changed

5 files changed

+5
-16
lines changed

pandas/core/generic.py

+1
Original file line numberDiff line numberDiff line change
@@ -12642,6 +12642,7 @@ def _inplace_method(self, other, op) -> Self:
1264212642
and result._indexed_same(self)
1264312643
and result.dtype == self.dtype
1264412644
and not using_copy_on_write()
12645+
and not (warn_copy_on_write() and not warn)
1264512646
):
1264612647
# GH#36498 this inplace op can _actually_ be inplace.
1264712648
# Item "ArrayManager" of "Union[ArrayManager, SingleArrayManager,

pandas/tests/frame/methods/test_quantile.py

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ def test_non_numeric_exclusion(self, interp_method, request, using_array_manager
110110
request.applymarker(pytest.mark.xfail(reason="Axis name incorrectly set."))
111111
tm.assert_series_equal(rs, xp)
112112

113-
# TODO(CoW-warn) should not need to warn
114-
@pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning")
115113
def test_axis(self, interp_method, request, using_array_manager):
116114
# axis
117115
interpolation, method = interp_method

pandas/tests/groupby/test_groupby.py

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def test_repr():
4141
assert result == expected
4242

4343

44-
# TODO(CoW-warn) this should NOT warn -> inplace operator triggers it
45-
@pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning")
4644
def test_groupby_std_datetimelike(warn_copy_on_write):
4745
# GH#48481
4846
tdi = pd.timedelta_range("1 Day", periods=10000)

pandas/tests/indexing/test_chaining_and_caching.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ def test_setitem_cache_updating_slices(
112112

113113
out = DataFrame({"A": [0, 0, 0]}, index=date_range("5/7/2014", "5/9/2014"))
114114
for ix, row in df.iterrows():
115-
# TODO(CoW-warn) should not warn
116-
with tm.assert_produces_warning(
117-
FutureWarning if warn_copy_on_write else None
118-
):
119-
out.loc[six:eix, row["C"]] += row["D"]
115+
out.loc[six:eix, row["C"]] += row["D"]
120116

121117
tm.assert_frame_equal(out, expected)
122118
tm.assert_series_equal(out["A"], expected["A"])

pandas/tests/indexing/test_iloc.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,7 @@ def test_iloc_getitem_slice_dups(self):
426426
tm.assert_frame_equal(df.iloc[10:, :2], df2)
427427
tm.assert_frame_equal(df.iloc[10:, 2:], df1)
428428

429-
# TODO(CoW-warn) this should NOT warn -> Series inplace operator
430-
@pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning")
431-
def test_iloc_setitem(self):
429+
def test_iloc_setitem(self, warn_copy_on_write):
432430
df = DataFrame(
433431
np.random.default_rng(2).standard_normal((4, 4)),
434432
index=np.arange(0, 8, 2),
@@ -1147,7 +1145,7 @@ def test_iloc_getitem_with_duplicates2(self):
11471145
expected = df.take([0], axis=1)
11481146
tm.assert_frame_equal(result, expected)
11491147

1150-
def test_iloc_interval(self, warn_copy_on_write):
1148+
def test_iloc_interval(self):
11511149
# GH#17130
11521150
df = DataFrame({Interval(1, 2): [1, 2]})
11531151

@@ -1160,9 +1158,7 @@ def test_iloc_interval(self, warn_copy_on_write):
11601158
tm.assert_series_equal(result, expected)
11611159

11621160
result = df.copy()
1163-
# TODO(CoW-warn) false positive
1164-
with tm.assert_cow_warning(warn_copy_on_write):
1165-
result.iloc[:, 0] += 1
1161+
result.iloc[:, 0] += 1
11661162
expected = DataFrame({Interval(1, 2): [2, 3]})
11671163
tm.assert_frame_equal(result, expected)
11681164

0 commit comments

Comments
 (0)