Skip to content

Commit 4e73f1e

Browse files
committed
Request For Help: unexplained ArrowInvalid overflow
1 parent 51763f9 commit 4e73f1e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,19 @@ def _box_pa_array(
500500
value = to_timedelta(value, unit=pa_type.unit).as_unit(pa_type.unit)
501501
value = value.to_numpy()
502502

503+
alt = None
504+
if pa_type is not None and pa.types.is_timestamp(pa_type):
505+
# Use to_datetime to handle NaNs, disallow Decimal("NaN")
506+
from pandas.core.tools.datetimes import to_datetime
507+
508+
new_value = to_datetime(value, unit=pa_type.unit).as_unit(pa_type.unit)
509+
alt = pa.array(np.asarray(new_value), type=pa_type, from_pandas=True)
510+
503511
try:
504512
pa_array = pa.array(value, type=pa_type, from_pandas=True)
513+
if alt is not None:
514+
assert alt == pa_array
515+
pa_array = alt
505516
except (pa.ArrowInvalid, pa.ArrowTypeError):
506517
# GH50430: let pyarrow infer type, then cast
507518
pa_array = pa.array(value, from_pandas=True)

0 commit comments

Comments
 (0)