Skip to content
Open
Show file tree
Hide file tree
Changes from all 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))
if pa.types.is_duration(arr.type):
# workaround for https://github.com/apache/arrow/issues/40620
result = ArrowExtensionArray._from_sequence(values)
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3700,3 +3700,15 @@ 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)


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