Skip to content

Commit

Permalink
Closes #22850
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Oct 2, 2018
1 parent a277e4a commit fdd43c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2324,9 +2324,11 @@ def combine(self, other, func, fill_value=None):
elif is_extension_array_dtype(self.values):
# The function can return something of any type, so check
# if the type is compatible with the calling EA
# ExtensionArray._from_sequence can raise anything, so we
# have to catch everything.
try:
new_values = self._values._from_sequence(new_values)
except TypeError:
except Exception:
pass

return self._constructor(new_values, index=new_index, name=new_name)
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/extension/test_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import operator
from decimal import Decimal

import pandas as pd
import pandas.util.testing as tm
from pandas.tests.extension.decimal.array import DecimalArray


def test_combine_from_sequence_raises():
# https://github.com/pandas-dev/pandas/issues/22850
class BadDecimalArray(DecimalArray):
def _from_sequence(cls, scalars, dtype=None, copy=False):
raise KeyError("For the test")

ser = pd.Series(BadDecimalArray([Decimal("1.0"), Decimal("2.0")]))
result = ser.combine(ser, operator.add)

# note: object dtype
expected = pd.Series([Decimal("2.0"), Decimal("4.0")], dtype="object")
tm.assert_series_equal(result, expected)

0 comments on commit fdd43c4

Please sign in to comment.