diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index d4f0e4681405b..8878a20bb5b42 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -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) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index c810f098f15cf..f39f7acdc57bf 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -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)