Skip to content

Akima interpolation bug #21276

@dershow

Description

@dershow

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime
from scipy import interpolate


df=pd.DataFrame([1,2,3,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,4,5],index=[pd.Timestamp('20180531 12:00:00'),pd.Timestamp('20180531 12:00:01'),pd.Timestamp('20180531 12:00:02.1'),pd.Timestamp('20180531 12:00:03.3'),pd.Timestamp('20180531 12:00:04'),pd.Timestamp('20180531 12:00:05'),pd.Timestamp('20180531 12:00:06.3'),pd.Timestamp('20180531 12:00:07'),pd.Timestamp('20180531 12:00:08'),pd.Timestamp('20180531 12:00:09'),pd.Timestamp('20180531 12:00:10.1')],columns=['data'])


df['akima']=df['data'].interpolate(method='akima')
df['pchip']=df['data'].interpolate(method='pchip')
df['time_interp']=df['data'].interpolate(method='time')
df['polynomial']=df['data'].interpolate(method='polynomial',order=3)


plt.plot(df['data'],'o')
plt.plot(df['akima'])
plt.plot(df['pchip'])
plt.plot(df['time_interp'])
plt.plot(df['polynomial'])

f_ak=interpolate.Akima1DInterpolator(df['data'].dropna().index.values.astype('d'),df['data'].dropna())

df['akima scipy']=f_ak(df['data'].index.values.astype('d'))

plt.plot(df['akima scipy'])

plt.legend()
plt.show()

Problem description

Interpolation using the akima method diverges from any reasonable expected result. Above I have some simple sample data, similar to my actual case, and other interpolators gives reasonable results, as demonstrated above. But, the akima method diverges away from the actual data.
I've also used the scipy akima interpolator explicitly above, and that works as expected. So, I would guess that there is a problem in how the data is being converted from pandas to scipy before Akima1DInterpolator is being called in pandas.

Expected Output

interplate(method='akima') should give results that are somewhat near to a linear interpolate, but instead they diverge.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Darwin
OS-release: 17.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.23.0
pytest: None
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.2
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 5.4.0
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: 4.1.1
bs4: 4.5.3
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions