Skip to content

Commit 288e319

Browse files
Backport PR pandas-dev#37986 on branch 1.1.x: REGR: fix inplace operations for EAs with non-EA arg (pandas-dev#38035)
Co-authored-by: Andrew Wieteska <[email protected]>
1 parent 77681d6 commit 288e319

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

doc/source/whatsnew/v1.1.5.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Fixed regressions
1717
- Regression in addition of a timedelta-like scalar to a :class:`DatetimeIndex` raising incorrectly (:issue:`37295`)
1818
- Fixed regression in :meth:`Series.groupby` raising when the :class:`Index` of the :class:`Series` had a tuple as its name (:issue:`37755`)
1919
- Fixed regression in :meth:`DataFrame.loc` and :meth:`Series.loc` for ``__setitem__`` when one-dimensional tuple was given to select from :class:`MultiIndex` (:issue:`37711`)
20-
-
20+
- Fixed regression in inplace operations on :class:`Series` with ``ExtensionDtype`` with NumPy dtyped operand (:issue:`37910`)
2121

2222
.. ---------------------------------------------------------------------------
2323

pandas/core/ops/methods.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import operator
55

6+
from pandas.core.dtypes.common import is_dtype_equal
67
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
78

89
from pandas.core.ops.roperator import (
@@ -97,7 +98,7 @@ def f(self, other):
9798
if (
9899
self.ndim == 1
99100
and result._indexed_same(self)
100-
and result.dtype == self.dtype
101+
and is_dtype_equal(result.dtype, self.dtype)
101102
):
102103
# GH#36498 this inplace op can _actually_ be inplace.
103104
self._values[:] = result._values

pandas/tests/scalar/timedelta/test_arithmetic.py

+1
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def test_td_div_numeric_scalar(self):
429429
_is_numpy_dev and not compat.PY39,
430430
raises=RuntimeWarning,
431431
reason="https://github.com/pandas-dev/pandas/issues/31992",
432+
strict=False,
432433
),
433434
),
434435
float("nan"),

pandas/tests/series/test_arithmetic.py

+27
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,30 @@ def test_datetime_understood(self):
687687
result = series - offset
688688
expected = pd.Series(pd.to_datetime(["2011-12-26", "2011-12-27", "2011-12-28"]))
689689
tm.assert_series_equal(result, expected)
690+
691+
692+
class TestInplaceOperations:
693+
@pytest.mark.parametrize(
694+
"dtype1, dtype2, dtype_expected, dtype_mul",
695+
(
696+
("Int64", "Int64", "Int64", "Int64"),
697+
("float", "float", "float", "float"),
698+
("Int64", "float", "float", "float"),
699+
),
700+
)
701+
def test_series_inplace_ops(self, dtype1, dtype2, dtype_expected, dtype_mul):
702+
# GH 37910
703+
704+
ser1 = Series([1], dtype=dtype1)
705+
ser2 = Series([2], dtype=dtype2)
706+
ser1 += ser2
707+
expected = Series([3], dtype=dtype_expected)
708+
tm.assert_series_equal(ser1, expected)
709+
710+
ser1 -= ser2
711+
expected = Series([1], dtype=dtype_expected)
712+
tm.assert_series_equal(ser1, expected)
713+
714+
ser1 *= ser2
715+
expected = Series([2], dtype=dtype_mul)
716+
tm.assert_series_equal(ser1, expected)

0 commit comments

Comments
 (0)