Skip to content

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

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
jeschwar opened this issue May 14, 2018 · 2 comments · Fixed by #29943
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@jeschwar
Copy link
Contributor

# define a Series to be used with interpolation to fill the NaN value
s = pd.Series(data=[10, 9, np.nan, 2, 1], index=[10,9,3,2,1])
# 10    10
# 9      9
# 3    nan
# 2      2
# 1      1

s.interpolate(method='index')
# returns the following; a 1 is used to fill the NaN which was not expected
# 10   10
# 9     9
# 3     1
# 2     2
# 1     1

s.sort_index(ascending=True).interpolate(method='index')
# returns the following; a 3 is used to correctly fill the NaN
# 1     1
# 2     2
# 3     3
# 9     9
# 10   10

Problem description

When calling .interpolate(method='index') on a Series or DataFrame where the Index is not sorted with ascending=True I think a warning should be raised to alert the user that errors in the output could be possible.

Output of pd.show_versions()

commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.22.0
pytest: 3.4.1
pip: 9.0.1
setuptools: 38.5.1
Cython: 0.27.3
numpy: 1.14.1
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.7.0
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: 2.5.0
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@ron819
Copy link

ron819 commented Oct 3, 2018

@jreback

@mroeschke
Copy link
Member

This looks like a bug to me. PRs and Investigations welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
4 participants