Skip to content

Commit 03181f0

Browse files
peterpanmjjorisvandenbossche
authored andcommitted
BUG: fix Series(extension array) + extension array values addition (#22479)
1 parent 04ea51d commit 03181f0

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

pandas/core/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ def dispatch_to_extension_op(op, left, right):
12181218
new_right = [new_right]
12191219
new_right = list(new_right)
12201220
elif is_extension_array_dtype(right) and type(left) != type(right):
1221-
new_right = list(new_right)
1221+
new_right = list(right)
12221222
else:
12231223
new_right = right
12241224

pandas/tests/extension/base/ops.py

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def test_divmod(self, data):
7777
self._check_divmod_op(s, divmod, 1, exc=TypeError)
7878
self._check_divmod_op(1, ops.rdivmod, s, exc=TypeError)
7979

80+
def test_add_series_with_extension_array(self, data):
81+
s = pd.Series(data)
82+
result = s + data
83+
expected = pd.Series(data + data)
84+
self.assert_series_equal(result, expected)
85+
8086
def test_error(self, data, all_arithmetic_operators):
8187
# invalid ops
8288
op_name = all_arithmetic_operators

pandas/tests/extension/json/test_json.py

+5
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ class TestArithmeticOps(BaseJSON, base.BaseArithmeticOpsTests):
261261
def test_error(self, data, all_arithmetic_operators):
262262
pass
263263

264+
def test_add_series_with_extension_array(self, data):
265+
ser = pd.Series(data)
266+
with tm.assert_raises_regex(TypeError, "unsupported"):
267+
ser + data
268+
264269

265270
class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests):
266271
pass

pandas/tests/extension/test_categorical.py

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from pandas.api.types import CategoricalDtype
2323
from pandas import Categorical
2424
from pandas.tests.extension import base
25+
import pandas.util.testing as tm
2526

2627

2728
def make_data():
@@ -202,6 +203,11 @@ def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
202203
else:
203204
pytest.skip('rmod never called when string is first argument')
204205

206+
def test_add_series_with_extension_array(self, data):
207+
ser = pd.Series(data)
208+
with tm.assert_raises_regex(TypeError, "cannot perform"):
209+
ser + data
210+
205211

206212
class TestComparisonOps(base.BaseComparisonOpsTests):
207213

pandas/tests/extension/test_integer.py

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ def test_error(self, data, all_arithmetic_operators):
143143
# other specific errors tested in the integer array specific tests
144144
pass
145145

146+
@pytest.mark.xfail(reason="EA is listified. GH-22922", strict=True)
147+
def test_add_series_with_extension_array(self, data):
148+
super(TestArithmeticOps, self).test_add_series_with_extension_array(
149+
data
150+
)
151+
146152

147153
class TestComparisonOps(base.BaseComparisonOpsTests):
148154

0 commit comments

Comments
 (0)