Skip to content

Pandas Interpolate Does not Handle Empty Values at Front of Series #10420

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

Closed
cancan101 opened this issue Jun 23, 2015 · 5 comments · Fixed by #10691
Closed

Pandas Interpolate Does not Handle Empty Values at Front of Series #10420

cancan101 opened this issue Jun 23, 2015 · 5 comments · Fixed by #10691
Labels
API Design Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@cancan101
Copy link
Contributor

This code means the interpolator won't handle extrapolating to the front of the Series even though the underlying implementations may have no problem with the extrapolation.

See for example UnivariateSpline whose default behavior is extrapolation.

Interpolation works fine at the end of the Series.

For example:

s = pd.Series([1, 2, 3, 4, np.nan, 6, np.nan])
s.interpolate(method='spline', order=1)
0    1
1    2
2    3
3    4
4    5
5    6
6    7
dtype: float64

but:

s = pd.Series([np.nan, 2, 3, 4, np.nan, 6, 7])
s.interpolate(method='spline', order=1)
0   NaN
1     2
2     3
3     4
4     5
5     6
6     7
dtype: float64
@jreback jreback added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Jun 23, 2015
@jreback
Copy link
Contributor

jreback commented Jun 23, 2015

hmm, I suppose that if the underlying can handle it then would be ok to change this. Try it and see if anything blows up. You might need to expand the tests a bit to make sure that this is all tested.

@jreback jreback added API Design Numeric Operations Arithmetic, Comparison, and Logical operations Difficulty Intermediate labels Jun 23, 2015
@jreback jreback added this to the Next Major Release milestone Jun 23, 2015
@lmjohns3
Copy link

This seems related to #9218 -- the only reason the values aren't filled at the beginning of the DataFrame/Series is that the fill for interpolate only happens forward.

@cancan101
Copy link
Contributor Author

Sure. This lines in the referenced ticket seems to sum it up:

The limit refers to forward filling only, even though interpolation is not inherently directional.

@lmjohns3
Copy link

Agreed.

Also see #10691 for an ongoing pull request/discussion.

@github-repo-health-uic
Copy link

This code means the interpolator won't handle extrapolating to the front of the Series even though the underlying implementations may have no problem with the extrapolation.

See for example UnivariateSpline whose default behavior is extrapolation.

Interpolation works fine at the end of the Series.

For example:

s = pd.Series([1, 2, 3, 4, np.nan, 6, np.nan])
s.interpolate(method='spline', order=1)
0    1
1    2
2    3
3    4
4    5
5    6
6    7
dtype: float64

but:

s = pd.Series([np.nan, 2, 3, 4, np.nan, 6, 7])
s.interpolate(method='spline', order=1)
0   NaN
1     2
2     3
3     4
4     5
5     6
6     7
dtype: float64

You can set limit_direction='both' . This is a parameter in the interpolation()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants