BUG: fix Series(extension array) + extension array values addition (#… · pandas-dev/pandas@03181f0 (original) (raw)

5 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -1218,7 +1218,7 @@ def dispatch_to_extension_op(op, left, right):
1218 1218 new_right = [new_right]
1219 1219 new_right = list(new_right)
1220 1220 elif is_extension_array_dtype(right) and type(left) != type(right):
1221 -new_right = list(new_right)
1221 +new_right = list(right)
1222 1222 else:
1223 1223 new_right = right
1224 1224
Original file line number Diff line number Diff line change
@@ -77,6 +77,12 @@ def test_divmod(self, data):
77 77 self._check_divmod_op(s, divmod, 1, exc=TypeError)
78 78 self._check_divmod_op(1, ops.rdivmod, s, exc=TypeError)
79 79
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 +
80 86 def test_error(self, data, all_arithmetic_operators):
81 87 # invalid ops
82 88 op_name = all_arithmetic_operators
Original file line number Diff line number Diff line change
@@ -261,6 +261,11 @@ class TestArithmeticOps(BaseJSON, base.BaseArithmeticOpsTests):
261 261 def test_error(self, data, all_arithmetic_operators):
262 262 pass
263 263
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 +
264 269
265 270 class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests):
266 271 pass
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
22 22 from pandas.api.types import CategoricalDtype
23 23 from pandas import Categorical
24 24 from pandas.tests.extension import base
25 +import pandas.util.testing as tm
25 26
26 27
27 28 def make_data():
@@ -202,6 +203,11 @@ def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
202 203 else:
203 204 pytest.skip('rmod never called when string is first argument')
204 205
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 +
205 211
206 212 class TestComparisonOps(base.BaseComparisonOpsTests):
207 213
Original file line number Diff line number Diff line change
@@ -143,6 +143,12 @@ def test_error(self, data, all_arithmetic_operators):
143 143 # other specific errors tested in the integer array specific tests
144 144 pass
145 145
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 +
146 152
147 153 class TestComparisonOps(base.BaseComparisonOpsTests):
148 154