40
40
from pandas .core .dtypes .dtypes import DatetimeTZDtype
41
41
from pandas .core .dtypes .missing import isna
42
42
43
- from pandas .core import roperator
43
+ from pandas .core import (
44
+ missing ,
45
+ roperator ,
46
+ )
44
47
from pandas .core .arraylike import OpsMixin
45
48
from pandas .core .arrays ._arrow_string_mixins import ArrowStringArrayMixin
46
49
from pandas .core .arrays .base import (
@@ -933,6 +936,20 @@ def pad_or_backfill(
933
936
# TODO(CoW): Not necessary anymore when CoW is the default
934
937
return self .copy ()
935
938
939
+ if limit is not None and limit_area is not None :
940
+ method = missing .clean_fill_method (method )
941
+ try :
942
+ if method == "pad" :
943
+ return type (self )(pc .fill_null_forward (self ._pa_array ))
944
+ elif method == "backfill" :
945
+ return type (self )(pc .fill_null_backward (self ._pa_array ))
946
+ except pa .ArrowNotImplementedError :
947
+ # ArrowNotImplementedError: Function 'coalesce' has no kernel
948
+ # matching input types (duration[ns], duration[ns])
949
+ # TODO: remove try/except wrapper if/when pyarrow implements
950
+ # a kernel for duration types.
951
+ pass
952
+
936
953
# TODO(3.0): after EA.fillna 'method' deprecation is enforced, we can remove
937
954
# this method entirely.
938
955
return super ().pad_or_backfill (
@@ -953,9 +970,12 @@ def fillna(
953
970
# TODO(CoW): Not necessary anymore when CoW is the default
954
971
return self .copy ()
955
972
956
- if limit is not None or method is not None :
973
+ if limit is not None :
957
974
return super ().fillna (value = value , method = method , limit = limit , copy = copy )
958
975
976
+ if method is not None :
977
+ return super ().pad_or_backfill (method = method , limit = limit , copy = copy )
978
+
959
979
if isinstance (value , (np .ndarray , ExtensionArray )):
960
980
# Similar to check_value_size, but we do not mask here since we may
961
981
# end up passing it to the super() method.
@@ -972,12 +992,7 @@ def fillna(
972
992
raise TypeError (msg ) from err
973
993
974
994
try :
975
- if method is None :
976
- return type (self )(pc .fill_null (self ._pa_array , fill_value = fill_value ))
977
- elif method == "pad" :
978
- return type (self )(pc .fill_null_forward (self ._pa_array ))
979
- elif method == "backfill" :
980
- return type (self )(pc .fill_null_backward (self ._pa_array ))
995
+ return type (self )(pc .fill_null (self ._pa_array , fill_value = fill_value ))
981
996
except pa .ArrowNotImplementedError :
982
997
# ArrowNotImplementedError: Function 'coalesce' has no kernel
983
998
# matching input types (duration[ns], duration[ns])
0 commit comments