Skip to content

Commit a4a2933

Browse files
committed
handle test
1 parent be63feb commit a4a2933

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

Diff for: pandas/core/arrays/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,8 @@ def convert_values(param):
777777
if coerce_to_dtype:
778778
try:
779779
res = self._from_sequence(res)
780-
except TypeError:
781-
pass
780+
except Exception:
781+
res = np.asarray(res, dtype=object)
782782

783783
return res
784784

Diff for: pandas/tests/extension/decimal/decimal_array/test_decimal.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,32 @@ def test_compare_array(self, data, all_compare_operators):
278278
self._compare_other(s, data, op_name, other)
279279

280280

281+
class DecimalArrayWithoutFromSequence(DecimalArray):
282+
"""Helper class for testing error handling in _from_sequence."""
283+
def _from_sequence(cls, scalars, dtype=None, copy=False):
284+
raise KeyError("For the test")
285+
286+
281287
def test_combine_from_sequence_raises():
282288
# https://github.com./pandas-dev/pandas/issues/22850
283-
class BadDecimalArray(DecimalArray):
284-
def _from_sequence(cls, scalars, dtype=None, copy=False):
285-
raise KeyError("For the test")
286-
287-
ser = pd.Series(BadDecimalArray([decimal.Decimal("1.0"),
288-
decimal.Decimal("2.0")]))
289+
ser = pd.Series(DecimalArrayWithoutFromSequence([
290+
decimal.Decimal("1.0"),
291+
decimal.Decimal("2.0")
292+
]))
289293
result = ser.combine(ser, operator.add)
290294

291295
# note: object dtype
292296
expected = pd.Series([decimal.Decimal("2.0"),
293297
decimal.Decimal("4.0")], dtype="object")
294298
tm.assert_series_equal(result, expected)
299+
300+
301+
def test_scalar_ops_from_sequence_raises():
302+
arr = DecimalArrayWithoutFromSequence([
303+
decimal.Decimal("1.0"),
304+
decimal.Decimal("2.0")
305+
])
306+
result = arr + arr
307+
expected = np.array([decimal.Decimal("2.0"), decimal.Decimal("4.0")],
308+
dtype="object")
309+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)