Skip to content

Commit fdd43c4

Browse files
committed
Closes #22850
1 parent a277e4a commit fdd43c4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pandas/core/series.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2324,9 +2324,11 @@ def combine(self, other, func, fill_value=None):
23242324
elif is_extension_array_dtype(self.values):
23252325
# The function can return something of any type, so check
23262326
# if the type is compatible with the calling EA
2327+
# ExtensionArray._from_sequence can raise anything, so we
2328+
# have to catch everything.
23272329
try:
23282330
new_values = self._values._from_sequence(new_values)
2329-
except TypeError:
2331+
except Exception:
23302332
pass
23312333

23322334
return self._constructor(new_values, index=new_index, name=new_name)

pandas/tests/extension/test_ops.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import operator
2+
from decimal import Decimal
3+
4+
import pandas as pd
5+
import pandas.util.testing as tm
6+
from pandas.tests.extension.decimal.array import DecimalArray
7+
8+
9+
def test_combine_from_sequence_raises():
10+
# https://github.com/pandas-dev/pandas/issues/22850
11+
class BadDecimalArray(DecimalArray):
12+
def _from_sequence(cls, scalars, dtype=None, copy=False):
13+
raise KeyError("For the test")
14+
15+
ser = pd.Series(BadDecimalArray([Decimal("1.0"), Decimal("2.0")]))
16+
result = ser.combine(ser, operator.add)
17+
18+
# note: object dtype
19+
expected = pd.Series([Decimal("2.0"), Decimal("4.0")], dtype="object")
20+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)