4040from pandas .core .dtypes .dtypes import DatetimeTZDtype
4141from pandas .core .dtypes .missing import isna
4242
43- from pandas .core import roperator
43+ from pandas .core import (
44+ missing ,
45+ roperator ,
46+ )
4447from pandas .core .arraylike import OpsMixin
4548from pandas .core .arrays ._arrow_string_mixins import ArrowStringArrayMixin
4649from pandas .core .arrays .base import (
@@ -933,6 +936,20 @@ def pad_or_backfill(
933936 # TODO(CoW): Not necessary anymore when CoW is the default
934937 return self .copy ()
935938
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+
936953 # TODO(3.0): after EA.fillna 'method' deprecation is enforced, we can remove
937954 # this method entirely.
938955 return super ().pad_or_backfill (
@@ -953,9 +970,12 @@ def fillna(
953970 # TODO(CoW): Not necessary anymore when CoW is the default
954971 return self .copy ()
955972
956- if limit is not None or method is not None :
973+ if limit is not None :
957974 return super ().fillna (value = value , method = method , limit = limit , copy = copy )
958975
976+ if method is not None :
977+ return super ().pad_or_backfill (method = method , limit = limit , copy = copy )
978+
959979 if isinstance (value , (np .ndarray , ExtensionArray )):
960980 # Similar to check_value_size, but we do not mask here since we may
961981 # end up passing it to the super() method.
@@ -972,12 +992,7 @@ def fillna(
972992 raise TypeError (msg ) from err
973993
974994 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 ))
981996 except pa .ArrowNotImplementedError :
982997 # ArrowNotImplementedError: Function 'coalesce' has no kernel
983998 # matching input types (duration[ns], duration[ns])
0 commit comments