Skip to content

Request For Help: unexplained ArrowInvalid overflow #61776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
11 changes: 11 additions & 0 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,19 @@ def _box_pa_array(
value = to_timedelta(value, unit=pa_type.unit).as_unit(pa_type.unit)
value = value.to_numpy()

alt = None
if pa_type is not None and pa.types.is_timestamp(pa_type):
# Use to_datetime to handle NaNs, disallow Decimal("NaN")
from pandas.core.tools.datetimes import to_datetime

new_value = to_datetime(value, unit=pa_type.unit).as_unit(pa_type.unit)
alt = pa.array(np.asarray(new_value), type=pa_type, from_pandas=True)

try:
pa_array = pa.array(value, type=pa_type, from_pandas=True)
if alt is not None:
assert alt == pa_array
pa_array = alt
except (pa.ArrowInvalid, pa.ArrowTypeError):
# GH50430: let pyarrow infer type, then cast
pa_array = pa.array(value, from_pandas=True)
Expand Down
Loading