@@ -755,7 +755,8 @@ def isna(self) -> np.ndarray | ExtensionArraySupportsAnyAll:
755755 If returning an ExtensionArray, then
756756
757757 * ``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`
759760 * ``na_values.any`` and ``na_values.all`` should be implemented
760761
761762 Examples
@@ -1058,19 +1059,12 @@ def fillna(
10581059 Alternatively, an array-like "value" can be given. It's expected
10591060 that the array-like have the same length as 'self'.
10601061 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.
10671063 copy : bool, default True
10681064 Whether to make a copy of the data before filling. If False, then
10691065 the original should be modified and no new memory should be allocated.
10701066 For ExtensionArray subclasses that cannot do this, it is at the
10711067 author's discretion whether to ignore "copy=False" or to raise.
1072- The base class implementation ignores the keyword in pad/backfill
1073- cases.
10741068
10751069 Returns
10761070 -------
@@ -1086,6 +1080,15 @@ def fillna(
10861080 Length: 6, dtype: Int64
10871081 """
10881082 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
10891092 # error: Argument 2 to "check_value_size" has incompatible type
10901093 # "ExtensionArray"; expected "ndarray"
10911094 value = missing .check_value_size (
0 commit comments