|
5 | 5 | import numpy as np
|
6 | 6 |
|
7 | 7 | from pandas._libs import algos, lib
|
8 |
| -from pandas._typing import Dtype, Hashable, Optional |
| 8 | +from pandas._typing import ArrayLike, Dtype, Hashable, Optional |
9 | 9 | from pandas.compat._optional import import_optional_dependency
|
10 | 10 |
|
11 | 11 | from pandas.core.dtypes.cast import infer_dtype_from_array
|
@@ -225,8 +225,6 @@ def interpolate_1d(
|
225 | 225 |
|
226 | 226 | preserve_nans = _derive_indices_of_nans_to_preserve(
|
227 | 227 | yvalues=yvalues,
|
228 |
| - valid=valid, |
229 |
| - invalid=invalid, |
230 | 228 | limit=limit,
|
231 | 229 | limit_area=limit_area,
|
232 | 230 | limit_direction=limit_direction,
|
@@ -290,15 +288,35 @@ def interpolate_1d(
|
290 | 288 |
|
291 | 289 |
|
292 | 290 | 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, |
294 | 295 | ):
|
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 |
296 | 298 | This function is called by `interpolate_1d` and takes the arguments with
|
297 | 299 | 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 |
299 | 301 | 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` |
300 | 315 | """
|
301 | 316 |
|
| 317 | + invalid = isna(yvalues) |
| 318 | + valid = ~invalid |
| 319 | + |
302 | 320 | # These are sets of index pointers to invalid values... i.e. {0, 1, etc...
|
303 | 321 | all_nans = set(np.flatnonzero(invalid))
|
304 | 322 | start_nans = set(range(find_valid_index(yvalues, "first")))
|
@@ -539,8 +557,6 @@ def interpolate_1d_fill(
|
539 | 557 |
|
540 | 558 | preserve_nans = _derive_indices_of_nans_to_preserve(
|
541 | 559 | yvalues=yvalues,
|
542 |
| - valid=valid, |
543 |
| - invalid=invalid, |
544 | 560 | limit=limit,
|
545 | 561 | limit_area=limit_area,
|
546 | 562 | limit_direction=limit_direction,
|
|
0 commit comments