raise warning when calling .interpolate(method='index') when Index is not sorted with ascending=True · Issue #21037 · pandas-dev/pandas (original) (raw)
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