Skip to content
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

BUG: Series.interpolate regression in latest Pandas 3.0.0 nightly (method 'linear' behaves like 'index') #61122

Closed
2 of 3 tasks
theOehrly opened this issue Mar 14, 2025 · 7 comments · Fixed by #61183
Closed
2 of 3 tasks
Assignees
Labels
Blocker Blocking issue or pull request for an upcoming release Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@theOehrly
Copy link
Contributor

theOehrly commented Mar 14, 2025

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • 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

Installed Versions

INSTALLED VERSIONS

commit : ddd0aa8
python : 3.12.1
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 3.0.0.dev0+2010.gddd0aa8dc7
numpy : 2.3.0.dev0+git20250311.a651643
dateutil : 2.9.0.post0
pip : 23.2.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.1
qtpy : None
pyqt5 : None

@theOehrly theOehrly added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 14, 2025
@rhshadrach
Copy link
Member

rhshadrach commented Mar 19, 2025

Thanks for the report! A git-bisect reveals:

4f7cb743533d21d3025f9b4fd2f4f1854977cc63 is the first bad commit
commit 4f7cb743533d21d3025f9b4fd2f4f1854977cc63
Author: Carlo Barth
Date:   Wed Apr 24 21:41:58 2024 +0200

    Fix/time series interpolation is wrong 21351 (#56515)

#56515

cc @cbpygit @mroeschke @MarcoGorelli

@rhshadrach
Copy link
Member

rhshadrach commented Mar 19, 2025

I believe this should be a simple partial revert of the linked PR. See #56515 (comment)

@rhshadrach rhshadrach added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Regression Functionality that used to work in a prior pandas version Blocker Blocking issue or pull request for an upcoming release and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 19, 2025
@rhshadrach rhshadrach added this to the 3.0 milestone Mar 19, 2025
@MarcoGorelli
Copy link
Member

nice, thanks for looking into it

I'm surprised the tests didn't catch this, probably too many tests using just the default (range) index

@rhshadrach
Copy link
Member

rhshadrach commented Mar 19, 2025

@MarcoGorelli - the tests did catch this. Doing the revert I suggested, three tests fail. In particular, this test:

https://github.com/pandas-dev/pandas/pull/56515/files#diff-d8f38fa35a17131c6df9125d090625806c0864ab083efd44511bb19ecd80701bR273

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Mar 19, 2025

oooh that's bad, I missed it when reviewing, this is on me (I probably thought it was one of the originally broken test cases which needed updating)

thanks @theOehrly for trying out the nightly build and reporting this!

@MarcoGorelli
Copy link
Member

@rhshadrach did you already have a fix ready?

I don't have capacity to think about this problem deeply enough at the moment (and in hindsight i shouldn't have taken on review of it to begin with), so if you don't i would be for just reverting the linked pr, as the previous behavior may well have been undesirable but at least it was as-documented

@rhshadrach
Copy link
Member

@MarcoGorelli - yes, indicated in #56515 (comment). I can take this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Blocking issue or pull request for an upcoming release Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants