Pandas version checks
-
[x] I have checked that this issue has not already been reported.
-
[ ] I have confirmed this bug exists on the latest version of pandas.
-
[x] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import numpy as np
import pandas as pd
s = pd.Series([1.0, np.nan, 3.0], index=[1, 3, 4])
s.interpolate(method='linear')
s.interpolate(method='index')
Issue Description
The interpolation method 'linear' behaves like the method 'index' with current Pandas 3.0.0 nightly. This is a regression from 2.2.3.
According to the documentation (stable and dev):
Interpolation technique to use. One of:
- ‘linear’: Ignore the index and treat the values as equally spaced. This is the only method supported on MultiIndexes. [...]
- ‘index’: The interpolation uses the numerical values of the DataFrame’s index to linearly calculate missing values.
In the example above, the index is not linearly spaced. But both interpolation methods return the output that is expected for the 'index' method when using the latest Pandas 3.0.0 nightly.
>>> s.interpolate(method='linear')
1 1.000000
3 2.333333
4 3.000000
dtype: float64
>>> s.interpolate(method='index')
1 1.000000
3 2.333333
4 3.000000
dtype: float64
Expected Behavior
The output should be different and 'linear'
should ignore the non-linearly spaced index. The expected output should be the same as with Pandas 2.2.3:
>>> s.interpolate(method='linear')
1 1.0
3 2.0
4 3.0
dtype: float64
>>> s.interpolate(method='index')
1 1.000000
3 2.333333
4 3.000000
dtype: float64