Skip to content

Commit 79eb377

Browse files
authored
BUG: _cast_pointwise_result([decimal_na]) (#62639)
1 parent 3f0e22f commit 79eb377

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ def _cast_pointwise_result(self, values) -> ArrayLike:
439439
# or test_agg_lambda_complex128_dtype_conversion for complex values
440440
return super()._cast_pointwise_result(values)
441441

442+
if pa.types.is_null(arr.type):
443+
if lib.infer_dtype(values) == "decimal":
444+
# GH#62522; the specific decimal precision here is arbitrary
445+
arr = arr.cast(pa.decimal128(1))
442446
if pa.types.is_duration(arr.type):
443447
# workaround for https://github.com/apache/arrow/issues/40620
444448
result = ArrowExtensionArray._from_sequence(values)

pandas/tests/extension/test_arrow.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,3 +3700,15 @@ def test_pow_with_all_na_float():
37003700
result = s.pow(2)
37013701
expected = pd.Series([pd.NA, pd.NA], dtype="float64[pyarrow]")
37023702
tm.assert_series_equal(result, expected)
3703+
3704+
3705+
def test_cast_pontwise_result_decimal_nan():
3706+
# GH#62522 we don't want to get back null[pyarrow] here
3707+
ser = pd.Series([], dtype="float64[pyarrow]")
3708+
arr = ser.array
3709+
item = Decimal("NaN")
3710+
3711+
result = arr._cast_pointwise_result([item])
3712+
3713+
pa_type = result.dtype.pyarrow_dtype
3714+
assert pa.types.is_decimal(pa_type)

0 commit comments

Comments
 (0)