diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 56001fabfdc9d..30646cea706e5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -12500,6 +12500,7 @@ def _inplace_method(self, other, op) -> Self: and result._indexed_same(self) and result.dtype == self.dtype and not using_copy_on_write() + and not (warn_copy_on_write() and not warn) ): # GH#36498 this inplace op can _actually_ be inplace. # Item "ArrayManager" of "Union[ArrayManager, SingleArrayManager, diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 787b77a5c725a..0f27eae1a3bfc 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -110,8 +110,6 @@ def test_non_numeric_exclusion(self, interp_method, request, using_array_manager request.applymarker(pytest.mark.xfail(reason="Axis name incorrectly set.")) tm.assert_series_equal(rs, xp) - # TODO(CoW-warn) should not need to warn - @pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning") def test_axis(self, interp_method, request, using_array_manager): # axis interpolation, method = interp_method diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 5b17484de9c93..3c6419ab86494 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -41,8 +41,6 @@ def test_repr(): assert result == expected -# TODO(CoW-warn) this should NOT warn -> inplace operator triggers it -@pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning") def test_groupby_std_datetimelike(warn_copy_on_write): # GH#48481 tdi = pd.timedelta_range("1 Day", periods=10000) diff --git a/pandas/tests/indexing/test_chaining_and_caching.py b/pandas/tests/indexing/test_chaining_and_caching.py index bf0975a803dce..a0ece7cd72cd8 100644 --- a/pandas/tests/indexing/test_chaining_and_caching.py +++ b/pandas/tests/indexing/test_chaining_and_caching.py @@ -121,11 +121,7 @@ def test_setitem_cache_updating_slices( out = DataFrame({"A": [0, 0, 0]}, index=date_range("5/7/2014", "5/9/2014")) for ix, row in df.iterrows(): - # TODO(CoW-warn) should not warn - with tm.assert_produces_warning( - FutureWarning if warn_copy_on_write else None - ): - out.loc[six:eix, row["C"]] += row["D"] + out.loc[six:eix, row["C"]] += row["D"] tm.assert_frame_equal(out, expected) tm.assert_series_equal(out["A"], expected["A"]) diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index baf2cdae43fe4..31263b44ed205 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -426,9 +426,7 @@ def test_iloc_getitem_slice_dups(self): tm.assert_frame_equal(df.iloc[10:, :2], df2) tm.assert_frame_equal(df.iloc[10:, 2:], df1) - # TODO(CoW-warn) this should NOT warn -> Series inplace operator - @pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning") - def test_iloc_setitem(self): + def test_iloc_setitem(self, warn_copy_on_write): df = DataFrame( np.random.default_rng(2).standard_normal((4, 4)), index=np.arange(0, 8, 2), @@ -1147,7 +1145,7 @@ def test_iloc_getitem_with_duplicates2(self): expected = df.take([0], axis=1) tm.assert_frame_equal(result, expected) - def test_iloc_interval(self, warn_copy_on_write): + def test_iloc_interval(self): # GH#17130 df = DataFrame({Interval(1, 2): [1, 2]}) @@ -1160,9 +1158,7 @@ def test_iloc_interval(self, warn_copy_on_write): tm.assert_series_equal(result, expected) result = df.copy() - # TODO(CoW-warn) false positive - with tm.assert_cow_warning(warn_copy_on_write): - result.iloc[:, 0] += 1 + result.iloc[:, 0] += 1 expected = DataFrame({Interval(1, 2): [2, 3]}) tm.assert_frame_equal(result, expected)