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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ def _cast_pointwise_result(self, values) -> ArrayLike:
# or test_agg_lambda_complex128_dtype_conversion for complex values
return super()._cast_pointwise_result(values)

if pa.types.is_null(arr.type):
if lib.infer_dtype(values) == "decimal":
# GH#62522; the specific decimal precision here is arbitrary
arr = arr.cast(pa.decimal32(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it would be nice to use a smaller 32 bit-width here, this API is only available in PyArrow 19 (evident by the xfail). I think we'll need to use decimal128 for our version compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, updated

if pa.types.is_duration(arr.type):
# workaround for https://github.com/apache/arrow/issues/40620
result = ArrowExtensionArray._from_sequence(values)
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3700,3 +3700,16 @@ def test_pow_with_all_na_float():
result = s.pow(2)
expected = pd.Series([pd.NA, pd.NA], dtype="float64[pyarrow]")
tm.assert_series_equal(result, expected)


@pytest.mark.xfail(pa_version_under14p0, reason="decimal32 not implemented")
def test_cast_pontwise_result_decimal_nan():
# GH#62522 we don't want to get back null[pyarrow] here
ser = pd.Series([], dtype="float64[pyarrow]")
arr = ser.array
item = Decimal("NaN")

result = arr._cast_pointwise_result([item])

pa_type = result.dtype.pyarrow_dtype
assert pa.types.is_decimal(pa_type)
Loading