Skip to content

Commit d8c8cbb

Browse files
authored
REGR: inplace Series op not actually operating inplace (#37508)
1 parent 5492ed7 commit d8c8cbb

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

doc/source/whatsnew/v1.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Fixed regressions
3030
- Fixed regression in setitem with :meth:`DataFrame.iloc` which raised error when trying to set a value while filtering with a boolean list (:issue:`36741`)
3131
- Fixed regression in setitem with a Series getting aligned before setting the values (:issue:`37427`)
3232
- Fixed regression in :attr:`MultiIndex.is_monotonic_increasing` returning wrong results with ``NaN`` in at least one of the levels (:issue:`37220`)
33+
- Fixed regression in inplace arithmetic operation on a Series not updating the parent DataFrame (:issue:`36373`)
3334

3435
.. ---------------------------------------------------------------------------
3536

pandas/core/generic.py

+5
Original file line numberDiff line numberDiff line change
@@ -11115,6 +11115,11 @@ def _inplace_method(self, other, op):
1111511115
"""
1111611116
result = op(self, other)
1111711117

11118+
if self.ndim == 1 and result._indexed_same(self) and result.dtype == self.dtype:
11119+
# GH#36498 this inplace op can _actually_ be inplace.
11120+
self._values[:] = result._values
11121+
return self
11122+
1111811123
# Delete cacher
1111911124
self._reset_cacher()
1112011125

pandas/tests/frame/test_arithmetic.py

+13
Original file line numberDiff line numberDiff line change
@@ -1698,3 +1698,16 @@ def test_arith_list_of_arraylike_raise(to_add):
16981698
df + to_add
16991699
with pytest.raises(ValueError, match=msg):
17001700
to_add + df
1701+
1702+
1703+
def test_inplace_arithmetic_series_update():
1704+
# https://github.com/pandas-dev/pandas/issues/36373
1705+
df = DataFrame({"A": [1, 2, 3]})
1706+
series = df["A"]
1707+
vals = series._values
1708+
1709+
series += 1
1710+
assert series._values is vals
1711+
1712+
expected = DataFrame({"A": [2, 3, 4]})
1713+
tm.assert_frame_equal(df, expected)

pandas/tests/indexing/test_loc.py

+1
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@ def test_identity_slice_returns_new_object(self):
888888
original_series[:3] = [7, 8, 9]
889889
assert all(sliced_series[:3] == [7, 8, 9])
890890

891+
@pytest.mark.xfail(reason="accidental fix reverted - GH37497")
891892
def test_loc_copy_vs_view(self):
892893
# GH 15631
893894
x = DataFrame(zip(range(3), range(3)), columns=["a", "b"])

0 commit comments

Comments
 (0)