@@ -755,7 +755,8 @@ def isna(self) -> np.ndarray | ExtensionArraySupportsAnyAll:
755
755
If returning an ExtensionArray, then
756
756
757
757
* ``na_values._is_boolean`` should be True
758
- * `na_values` should implement :func:`ExtensionArray._reduce`
758
+ * ``na_values`` should implement :func:`ExtensionArray._reduce`
759
+ * ``na_values`` should implement :func:`ExtensionArray._accumulate`
759
760
* ``na_values.any`` and ``na_values.all`` should be implemented
760
761
761
762
Examples
@@ -1058,19 +1059,12 @@ def fillna(
1058
1059
Alternatively, an array-like "value" can be given. It's expected
1059
1060
that the array-like have the same length as 'self'.
1060
1061
limit : int, default None
1061
- If method is specified, this is the maximum number of consecutive
1062
- NaN values to forward/backward fill. In other words, if there is
1063
- a gap with more than this number of consecutive NaNs, it will only
1064
- be partially filled. If method is not specified, this is the
1065
- maximum number of entries along the entire axis where NaNs will be
1066
- filled.
1062
+ The maximum number of entries where NA values will be filled.
1067
1063
copy : bool, default True
1068
1064
Whether to make a copy of the data before filling. If False, then
1069
1065
the original should be modified and no new memory should be allocated.
1070
1066
For ExtensionArray subclasses that cannot do this, it is at the
1071
1067
author's discretion whether to ignore "copy=False" or to raise.
1072
- The base class implementation ignores the keyword in pad/backfill
1073
- cases.
1074
1068
1075
1069
Returns
1076
1070
-------
@@ -1086,6 +1080,15 @@ def fillna(
1086
1080
Length: 6, dtype: Int64
1087
1081
"""
1088
1082
mask = self .isna ()
1083
+ if limit is not None and limit < len (self ):
1084
+ # isna can return an ExtensionArray, we're assuming that comparisons
1085
+ # are implemented.
1086
+ # mypy doesn't like that mask can be an EA which need not have `cumsum`
1087
+ modify = mask .cumsum () > limit # type: ignore[union-attr]
1088
+ if modify .any ():
1089
+ # Only copy mask if necessary
1090
+ mask = mask .copy ()
1091
+ mask [modify ] = False
1089
1092
# error: Argument 2 to "check_value_size" has incompatible type
1090
1093
# "ExtensionArray"; expected "ndarray"
1091
1094
value = missing .check_value_size (
0 commit comments