Skip to content

Commit 0bb36de

Browse files
committed
Added type annotation, updated docstring and removed unnecessary arguments
Test on my local machine are not affected by removing the unncessery arguments `valid` and `invalid`, which are now derived within the function.
1 parent c5b77d2 commit 0bb36de

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

pandas/core/missing.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
from pandas._libs import algos, lib
8-
from pandas._typing import Dtype, Hashable, Optional
8+
from pandas._typing import ArrayLike, Dtype, Hashable, Optional
99
from pandas.compat._optional import import_optional_dependency
1010

1111
from pandas.core.dtypes.cast import infer_dtype_from_array
@@ -225,8 +225,6 @@ def interpolate_1d(
225225

226226
preserve_nans = _derive_indices_of_nans_to_preserve(
227227
yvalues=yvalues,
228-
valid=valid,
229-
invalid=invalid,
230228
limit=limit,
231229
limit_area=limit_area,
232230
limit_direction=limit_direction,
@@ -290,15 +288,35 @@ def interpolate_1d(
290288

291289

292290
def _derive_indices_of_nans_to_preserve(
293-
yvalues, valid, invalid, limit, limit_area, limit_direction
291+
yvalues: ArrayLike,
292+
limit: int,
293+
limit_area: str,
294+
limit_direction: str,
294295
):
295-
""" Derive the indices of NaNs that shall be preserved after interpolation
296+
"""
297+
Derive the indices of NaNs that shall be preserved after interpolation
296298
This function is called by `interpolate_1d` and takes the arguments with
297299
the same name from there. In `interpolate_1d`, after performing the
298-
interpolation the list of indices of NaNs to preserve is used to put
300+
interpolation, the list of indices of NaNs to preserve is used to put
299301
NaNs in the desired locations.
302+
303+
Parameters
304+
----------
305+
yvalues: ArrayLike
306+
1-d array of values of the initial Series or DataFrame
307+
limit: int
308+
limit_area: str
309+
limit_direction: str
310+
311+
Returns
312+
-------
313+
preserve_nans: set
314+
Set of index pointers to where NaNs should be preserved in `yvalues`
300315
"""
301316

317+
invalid = isna(yvalues)
318+
valid = ~invalid
319+
302320
# These are sets of index pointers to invalid values... i.e. {0, 1, etc...
303321
all_nans = set(np.flatnonzero(invalid))
304322
start_nans = set(range(find_valid_index(yvalues, "first")))
@@ -539,8 +557,6 @@ def interpolate_1d_fill(
539557

540558
preserve_nans = _derive_indices_of_nans_to_preserve(
541559
yvalues=yvalues,
542-
valid=valid,
543-
invalid=invalid,
544560
limit=limit,
545561
limit_area=limit_area,
546562
limit_direction=limit_direction,

0 commit comments

Comments
 (0)