Skip to content

Commit aa4bd7d

Browse files
committed
follow-up to pandas-dev#29314
1 parent 023fa0c commit aa4bd7d

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

pandas/_libs/algos.pyx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,18 @@ ctypedef fused algos_t:
380380

381381

382382
def _validate_limit(nobs: int, limit=None) -> int:
383+
"""
384+
Check that the `limit` argument is a positive integer.
385+
386+
Parameters
387+
----------
388+
nobs : int
389+
limit : object
390+
391+
Returns
392+
-------
393+
int
394+
"""
383395
if limit is None:
384396
lim = nobs
385397
else:

pandas/core/internals/blocks.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99

10-
from pandas._libs import NaT, lib, tslib, writers
10+
from pandas._libs import NaT, algos as libalgos, lib, tslib, writers
1111
from pandas._libs.index import convert_scalar
1212
import pandas._libs.internals as libinternals
1313
from pandas._libs.tslibs import Timedelta, conversion
@@ -393,10 +393,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
393393

394394
mask = isna(self.values)
395395
if limit is not None:
396-
if not is_integer(limit):
397-
raise ValueError("Limit must be an integer")
398-
if limit < 1:
399-
raise ValueError("Limit must be greater than 0")
396+
limit = libalgos._validate_limit(None, limit=limit)
400397
mask[mask.cumsum(self.ndim - 1) > limit] = False
401398

402399
if not self._can_hold_na:

pandas/core/missing.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
ensure_float64,
1212
is_datetime64_dtype,
1313
is_datetime64tz_dtype,
14-
is_integer,
1514
is_integer_dtype,
1615
is_numeric_v_string_like,
1716
is_scalar,
@@ -191,13 +190,7 @@ def interpolate_1d(
191190
)
192191

193192
# default limit is unlimited GH #16282
194-
if limit is None:
195-
# limit = len(xvalues)
196-
pass
197-
elif not is_integer(limit):
198-
raise ValueError("Limit must be an integer")
199-
elif limit < 1:
200-
raise ValueError("Limit must be greater than 0")
193+
limit = algos._validate_limit(nobs=None, limit=limit)
201194

202195
from pandas import Series
203196

0 commit comments

Comments
 (0)