Skip to content

Commit

Permalink
BUG: fix Series(extension array) + extension array values addition (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpanmj authored and jorisvandenbossche committed Oct 3, 2018
1 parent 04ea51d commit 03181f0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/ops.py
Expand Up @@ -1218,7 +1218,7 @@ def dispatch_to_extension_op(op, left, right):
new_right = [new_right]
new_right = list(new_right)
elif is_extension_array_dtype(right) and type(left) != type(right):
new_right = list(new_right)
new_right = list(right)
else:
new_right = right

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/extension/base/ops.py
Expand Up @@ -77,6 +77,12 @@ def test_divmod(self, data):
self._check_divmod_op(s, divmod, 1, exc=TypeError)
self._check_divmod_op(1, ops.rdivmod, s, exc=TypeError)

def test_add_series_with_extension_array(self, data):
s = pd.Series(data)
result = s + data
expected = pd.Series(data + data)
self.assert_series_equal(result, expected)

def test_error(self, data, all_arithmetic_operators):
# invalid ops
op_name = all_arithmetic_operators
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/extension/json/test_json.py
Expand Up @@ -261,6 +261,11 @@ class TestArithmeticOps(BaseJSON, base.BaseArithmeticOpsTests):
def test_error(self, data, all_arithmetic_operators):
pass

def test_add_series_with_extension_array(self, data):
ser = pd.Series(data)
with tm.assert_raises_regex(TypeError, "unsupported"):
ser + data


class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests):
pass
6 changes: 6 additions & 0 deletions pandas/tests/extension/test_categorical.py
Expand Up @@ -22,6 +22,7 @@
from pandas.api.types import CategoricalDtype
from pandas import Categorical
from pandas.tests.extension import base
import pandas.util.testing as tm


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

def test_add_series_with_extension_array(self, data):
ser = pd.Series(data)
with tm.assert_raises_regex(TypeError, "cannot perform"):
ser + data


class TestComparisonOps(base.BaseComparisonOpsTests):

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/extension/test_integer.py
Expand Up @@ -143,6 +143,12 @@ def test_error(self, data, all_arithmetic_operators):
# other specific errors tested in the integer array specific tests
pass

@pytest.mark.xfail(reason="EA is listified. GH-22922", strict=True)
def test_add_series_with_extension_array(self, data):
super(TestArithmeticOps, self).test_add_series_with_extension_array(
data
)


class TestComparisonOps(base.BaseComparisonOpsTests):

Expand Down

0 comments on commit 03181f0

Please sign in to comment.