Skip to content

Commit

Permalink
handle test
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Oct 2, 2018
1 parent be63feb commit a4a2933
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ def convert_values(param):
if coerce_to_dtype:
try:
res = self._from_sequence(res)
except TypeError:
pass
except Exception:
res = np.asarray(res, dtype=object)

return res

Expand Down
27 changes: 21 additions & 6 deletions pandas/tests/extension/decimal/decimal_array/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,32 @@ def test_compare_array(self, data, all_compare_operators):
self._compare_other(s, data, op_name, other)


class DecimalArrayWithoutFromSequence(DecimalArray):
"""Helper class for testing error handling in _from_sequence."""
def _from_sequence(cls, scalars, dtype=None, copy=False):
raise KeyError("For the test")


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.Decimal("1.0"),
decimal.Decimal("2.0")]))
ser = pd.Series(DecimalArrayWithoutFromSequence([
decimal.Decimal("1.0"),
decimal.Decimal("2.0")
]))
result = ser.combine(ser, operator.add)

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


def test_scalar_ops_from_sequence_raises():
arr = DecimalArrayWithoutFromSequence([
decimal.Decimal("1.0"),
decimal.Decimal("2.0")
])
result = arr + arr
expected = np.array([decimal.Decimal("2.0"), decimal.Decimal("4.0")],
dtype="object")
tm.assert_numpy_array_equal(result, expected)

0 comments on commit a4a2933

Please sign in to comment.