Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,7 @@ def _box_pa_array(
else:
try:
pa_array = pa_array.cast(pa_type)
except (
pa.ArrowInvalid,
pa.ArrowTypeError,
pa.ArrowNotImplementedError,
):
except (pa.ArrowNotImplementedError, pa.ArrowTypeError):
if pa.types.is_string(pa_array.type) or pa.types.is_large_string(
pa_array.type
):
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,30 @@ def test_pow_missing_operand():
tm.assert_series_equal(result, expected)


@pytest.mark.skipif(
pa_version_under11p0, reason="Decimal128 to string cast implemented in pyarrow 11"
)
def test_decimal_parse_raises():
# GH 56984
ser = pd.Series(["1.2345"], dtype=ArrowDtype(pa.string()))
with pytest.raises(
pa.lib.ArrowInvalid, match="Rescaling Decimal128 value would cause data loss"
):
ser.astype(ArrowDtype(pa.decimal128(1, 0)))


@pytest.mark.skipif(
pa_version_under11p0, reason="Decimal128 to string cast implemented in pyarrow 11"
)
def test_decimal_parse_succeeds():
# GH 56984
ser = pd.Series(["1.2345"], dtype=ArrowDtype(pa.string()))
dtype = ArrowDtype(pa.decimal128(5, 4))
result = ser.astype(dtype)
expected = pd.Series([Decimal("1.2345")], dtype=dtype)
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("pa_type", tm.TIMEDELTA_PYARROW_DTYPES)
def test_duration_fillna_numpy(pa_type):
# GH 54707
Expand Down