Skip to content

Commit 20f7ffa

Browse files
authored
REGR: fix inplace operations for EAs with non-EA arg (#37986)
1 parent 2c1e981 commit 20f7ffa

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-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/generic.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
is_datetime64_any_dtype,
7171
is_datetime64tz_dtype,
7272
is_dict_like,
73+
is_dtype_equal,
7374
is_extension_array_dtype,
7475
is_float,
7576
is_list_like,
@@ -11266,7 +11267,11 @@ def _inplace_method(self, other, op):
1126611267
"""
1126711268
result = op(self, other)
1126811269

11269-
if self.ndim == 1 and result._indexed_same(self) and result.dtype == self.dtype:
11270+
if (
11271+
self.ndim == 1
11272+
and result._indexed_same(self)
11273+
and is_dtype_equal(result.dtype, self.dtype)
11274+
):
1127011275
# GH#36498 this inplace op can _actually_ be inplace.
1127111276
self._values[:] = result._values
1127211277
return self

pandas/tests/series/test_arithmetic.py

+34
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,40 @@ def test_scalarop_preserve_name(self, datetime_series):
832832
assert result.name == datetime_series.name
833833

834834

835+
class TestInplaceOperations:
836+
@pytest.mark.parametrize(
837+
"dtype1, dtype2, dtype_expected, dtype_mul",
838+
(
839+
("Int64", "Int64", "Int64", "Int64"),
840+
("float", "float", "float", "float"),
841+
("Int64", "float", "float", "float"),
842+
pytest.param(
843+
"Int64",
844+
"Float64",
845+
"Float64",
846+
"Float64",
847+
marks=pytest.mark.xfail(reason="Not implemented yet"),
848+
),
849+
),
850+
)
851+
def test_series_inplace_ops(self, dtype1, dtype2, dtype_expected, dtype_mul):
852+
# GH 37910
853+
854+
ser1 = Series([1], dtype=dtype1)
855+
ser2 = Series([2], dtype=dtype2)
856+
ser1 += ser2
857+
expected = Series([3], dtype=dtype_expected)
858+
tm.assert_series_equal(ser1, expected)
859+
860+
ser1 -= ser2
861+
expected = Series([1], dtype=dtype_expected)
862+
tm.assert_series_equal(ser1, expected)
863+
864+
ser1 *= ser2
865+
expected = Series([2], dtype=dtype_mul)
866+
tm.assert_series_equal(ser1, expected)
867+
868+
835869
def test_none_comparison(series_with_simple_index):
836870
series = series_with_simple_index
837871
if isinstance(series.index, IntervalIndex):

0 commit comments

Comments
 (0)