-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG in Series.interpolate: limit_area/limit_direction kwargs with method="pad"/"bfill" have no effect #38106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 42 commits
9afe992
3a191b9
fd5d8e8
26d88ed
6597aca
c536d3c
ed9cf21
2980325
ecf428e
f8a3423
6733186
c5b77d2
0bb36de
a467afd
5466d8c
3e968fc
556a3cf
6c1e429
767b0ca
b82aaff
26ef7b5
b4b6b5a
e259549
8ceff58
7c5ad7d
92148ff
d62e02e
c2473f2
610e347
570e3c2
721304a
73ab1bf
a33f629
64e03ec
80e2a78
cb9d56a
3aa6efa
47064b6
bd2e0cc
8a01725
e2e7f61
69bae74
e18f43d
cc898a9
5ee59ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
""" | ||
Routines for filling missing data. | ||
""" | ||
|
||
from functools import partial | ||
from typing import Any, List, Optional, Set, Union | ||
|
||
import numpy as np | ||
|
||
from pandas._libs import algos, lib | ||
from pandas._typing import ArrayLike, DtypeObj | ||
from pandas._typing import ArrayLike, Axis, DtypeObj | ||
from pandas.compat._optional import import_optional_dependency | ||
|
||
from pandas.core.dtypes.cast import infer_dtype_from_array | ||
|
@@ -528,16 +528,99 @@ def _cubicspline_interpolate(xi, yi, x, axis=0, bc_type="not-a-knot", extrapolat | |
return P(x) | ||
|
||
|
||
def _interpolate_with_limit_area( | ||
values: ArrayLike, method: str, limit: Optional[int], limit_area: Optional[str] | ||
) -> ArrayLike: | ||
""" | ||
Apply interpolation and limit_area logic to values along a to-be-specified axis. | ||
|
||
Parameters | ||
---------- | ||
values: array-like | ||
Input array. | ||
method: str | ||
Interpolation method. Could be "bfill" or "pad" | ||
limit: int, optional | ||
Index limit on interpolation. | ||
limit_area: str | ||
Limit area for interpolation. Can be "inside" or "outside" | ||
|
||
Returns | ||
------- | ||
values: array-like | ||
Interpolated array. | ||
""" | ||
|
||
invalid = isna(values) | ||
|
||
if not invalid.any(): | ||
pass | ||
elif not invalid.all(): | ||
first = find_valid_index(values, "first") | ||
last = find_valid_index(values, "last") | ||
|
||
values = interpolate_2d( | ||
values, | ||
method=method, | ||
limit=limit, | ||
) | ||
|
||
if limit_area == "inside": | ||
invalid[first : last + 1] = False | ||
elif limit_area == "outside": | ||
invalid[:first] = invalid[last + 1 :] = False | ||
|
||
values[invalid] = np.nan | ||
else: | ||
values = interpolate_2d( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is hit? (this is weird because its called from interpolate_2d itself). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactored this away (leftover from original PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was hit for one example but |
||
values, | ||
method=method, | ||
limit=limit, | ||
) | ||
return values | ||
|
||
|
||
def interpolate_2d( | ||
values, | ||
method="pad", | ||
axis=0, | ||
limit=None, | ||
method: str = "pad", | ||
axis: Axis = 0, | ||
limit: Optional[int] = None, | ||
limit_area: Optional[str] = None, | ||
): | ||
""" | ||
Perform an actual interpolation of values, values will be make 2-d if | ||
needed fills inplace, returns the result. | ||
|
||
Parameters | ||
---------- | ||
values: array-like | ||
Input array. | ||
method: str, default "pad" | ||
Interpolation method. Could be "bfill" or "pad" | ||
axis: 0 or 1 | ||
Interpolation axis | ||
limit: int, optional | ||
Index limit on interpolation. | ||
limit_area: str, optional | ||
Limit area for interpolation. Can be "inside" or "outside" | ||
|
||
Returns | ||
------- | ||
values: array-like | ||
Interpolated array. | ||
""" | ||
if limit_area is not None: | ||
return np.apply_along_axis( | ||
partial( | ||
_interpolate_with_limit_area, | ||
method=method, | ||
limit=limit, | ||
limit_area=limit_area, | ||
), | ||
axis, | ||
values, | ||
) | ||
|
||
orig_values = values | ||
|
||
transf = (lambda x: x) if axis == 0 else (lambda x: x.T) | ||
|
Uh oh!
There was an error while loading. Please reload this page.