diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1674960f21b19..ed942052eccea 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -12398,7 +12398,12 @@ def _inplace_method(self, other, op) -> Self: result = op(self, other) - if self.ndim == 1 and result._indexed_same(self) and result.dtype == self.dtype: + if ( + self.ndim == 1 + and result._indexed_same(self) + and result.dtype == self.dtype + and not using_copy_on_write() + ): # GH#36498 this inplace op can _actually_ be inplace. # Item "ArrayManager" of "Union[ArrayManager, SingleArrayManager, # BlockManager, SingleBlockManager]" has no attribute "setitem_inplace" diff --git a/pandas/tests/copy_view/test_methods.py b/pandas/tests/copy_view/test_methods.py index 73bb9b4a71741..4cfa56d1431a1 100644 --- a/pandas/tests/copy_view/test_methods.py +++ b/pandas/tests/copy_view/test_methods.py @@ -1806,12 +1806,22 @@ def test_update_chained_assignment(using_copy_on_write): tm.assert_frame_equal(df, df_orig) -def test_inplace_arithmetic_series(): +def test_inplace_arithmetic_series(using_copy_on_write): ser = Series([1, 2, 3]) + ser_orig = ser.copy() data = get_array(ser) ser *= 2 - assert np.shares_memory(get_array(ser), data) - tm.assert_numpy_array_equal(data, get_array(ser)) + if using_copy_on_write: + # https://github.com/pandas-dev/pandas/pull/55745 + # changed to NOT update inplace because there is no benefit (actual + # operation already done non-inplace). This was only for the optics + # of updating the backing array inplace, but we no longer want to make + # that guarantee + assert not np.shares_memory(get_array(ser), data) + tm.assert_numpy_array_equal(data, get_array(ser_orig)) + else: + assert np.shares_memory(get_array(ser), data) + tm.assert_numpy_array_equal(data, get_array(ser)) def test_inplace_arithmetic_series_with_reference(