@@ -381,8 +381,7 @@ def _box_pa_scalar(cls, value, pa_type: pa.DataType | None = None) -> pa.Scalar:
381
381
elif isna (value ):
382
382
pa_scalar = pa .scalar (None , type = pa_type )
383
383
else :
384
- # GH 53171: pyarrow does not yet handle pandas non-nano correctly
385
- # see https://github.com/apache/arrow/issues/33321
384
+ # Workaround https://github.com/apache/arrow/issues/37291
386
385
if isinstance (value , Timedelta ):
387
386
if pa_type is None :
388
387
pa_type = pa .duration (value .unit )
@@ -448,8 +447,7 @@ def _box_pa_array(
448
447
and pa .types .is_duration (pa_type )
449
448
and (not isinstance (value , np .ndarray ) or value .dtype .kind not in "mi" )
450
449
):
451
- # GH 53171: pyarrow does not yet handle pandas non-nano correctly
452
- # see https://github.com/apache/arrow/issues/33321
450
+ # Workaround https://github.com/apache/arrow/issues/37291
453
451
from pandas .core .tools .timedeltas import to_timedelta
454
452
455
453
value = to_timedelta (value , unit = pa_type .unit ).as_unit (pa_type .unit )
@@ -462,8 +460,7 @@ def _box_pa_array(
462
460
pa_array = pa .array (value , from_pandas = True )
463
461
464
462
if pa_type is None and pa .types .is_duration (pa_array .type ):
465
- # GH 53171: pyarrow does not yet handle pandas non-nano correctly
466
- # see https://github.com/apache/arrow/issues/33321
463
+ # Workaround https://github.com/apache/arrow/issues/37291
467
464
from pandas .core .tools .timedeltas import to_timedelta
468
465
469
466
value = to_timedelta (value )
@@ -965,26 +962,11 @@ def fillna(
965
962
f" expected { len (self )} "
966
963
)
967
964
968
- def convert_fill_value (value , pa_type , dtype ):
969
- if value is None :
970
- return value
971
- if isinstance (value , (pa .Scalar , pa .Array , pa .ChunkedArray )):
972
- return value
973
- if isinstance (value , Timedelta ) and value .unit in ("s" , "ms" ):
974
- # Workaround https://github.com/apache/arrow/issues/37291
975
- value = value .to_numpy ()
976
- if is_array_like (value ):
977
- pa_box = pa .array
978
- else :
979
- pa_box = pa .scalar
980
- try :
981
- value = pa_box (value , type = pa_type , from_pandas = True )
982
- except pa .ArrowTypeError as err :
983
- msg = f"Invalid value '{ str (value )} ' for dtype { dtype } "
984
- raise TypeError (msg ) from err
985
- return value
986
-
987
- fill_value = convert_fill_value (value , self ._pa_array .type , self .dtype )
965
+ try :
966
+ fill_value = self ._box_pa (value , pa_type = self ._pa_array .type )
967
+ except pa .ArrowTypeError as err :
968
+ msg = f"Invalid value '{ str (value )} ' for dtype { self .dtype } "
969
+ raise TypeError (msg ) from err
988
970
989
971
try :
990
972
if method is None :
0 commit comments