File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments