Skip to content

ENH: warn Series.interpolate(method='index') with unsorted index #29887

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

Conversation

immaxchen
Copy link
Contributor

Series.interpolate(method='index') use numpy.interp under the hood, which, from numpy doc, Does not check that the x-coordinate sequence xp is increasing. If xp is not increasing, the results are nonsense. (link)
Here adds a warning to warn the user about this.

@WillAyd
Copy link
Member

WillAyd commented Nov 27, 2019

Can this be fixed instead of producing a warning?

@immaxchen
Copy link
Contributor Author

immaxchen commented Nov 27, 2019

Yes it can, in the cost of introducing dependency on scipy. (like other interpolate methods)

@WillAyd
Copy link
Member

WillAyd commented Nov 27, 2019

We can't use pd.where(..., df.index) to fill from the index?

@immaxchen
Copy link
Contributor Author

You mean we sort it, interpolate, then fill it back? this may leads to undefined behavior for duplicated indexes, better leaves the responsibility to scipy IMHO. 😂

@jreback
Copy link
Contributor

jreback commented Nov 27, 2019

You mean we sort it, interpolate, then fill it back? this may leads to undefined behavior for duplicated indexes, better leaves the responsibility to scipy IMHO. 😂

then would just raise rather than a warning.

@immaxchen
Copy link
Contributor Author

So the preferred approach would be stick to numpy.interp but we do the sort for it right? No problem. I will close this one and do it in a new branch. Thanks for your suggestions.

@immaxchen immaxchen closed this Nov 28, 2019
@jreback
Copy link
Contributor

jreback commented Nov 28, 2019

i think either we sort then reorder to get the original
or raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

raise warning when calling .interpolate(method='index') when Index is not sorted with ascending=True
3 participants