diff --git a/pandas/core/series.py b/pandas/core/series.py index 83f80c305c5eb..7c1192374fc44 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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) diff --git a/pandas/tests/extension/test_ops.py b/pandas/tests/extension/test_ops.py new file mode 100644 index 0000000000000..5d23fc8bf899a --- /dev/null +++ b/pandas/tests/extension/test_ops.py @@ -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)