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

API/DEPR: interpolate with object dtype #53631

Closed
jbrockmendel opened this issue Jun 12, 2023 · 2 comments · Fixed by #53638
Closed

API/DEPR: interpolate with object dtype #53631

jbrockmendel opened this issue Jun 12, 2023 · 2 comments · Fixed by #53638
Labels
API Design Deprecate Functionality to remove in pandas Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Jun 12, 2023

import pandas as pd
import numpy as np

ser = pd.Series([1, np.nan, 2], dtype=object)

>>> ser.interpolate()
0      1
1    NaN
2      2
dtype: object

ATM if we have object-dtype, interpolate is incorrectly a no-op. (In the DataFrame case we have a weird check that raises on all-object).

If we disable the check in Block.interpolate if m is None and self.dtype.kind != "f": that short-circuits, then the OP case raises in np.interp when trying to cast to float64.

The viable options I see are:

  1. Raise on object dtype, tell users to do .infer_objects() before calling interpolate.
  2. Check if there the array has any NaNs. if not, short-circuit as in the status quo. Otherwise goto 1).

I lean towards "do 2) immediately and 1) with a deprecation cycle".

(I haven't checked the scipy paths, just the numpy one)

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 12, 2023
@topper-123
Copy link
Contributor

Sounds good to me.

@topper-123 topper-123 added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate API Design Deprecate Functionality to remove in pandas and removed Needs Triage Issue that has not been reviewed by a pandas team member Bug labels Jun 13, 2023
@verglasz
Copy link

verglasz commented Dec 13, 2023

I am currently using resample().interpolate() on a dataframe with a datetime index and which has some numeric columns and some columns with python strings, and the current (deprecated) behaviour is very convenient, I can fill the NaNs left in the string column with appropriate information based on the interpolation or other details or call some other method like bfill/ffill to take care of those.
Once this will error, what would be the approach to achieve the same result? Separate the numeric and object columns and call separately resample().interpolate() on the first set and resample().fillna() on the second, then put the df back together?
Imho it would be nice to keep some way of accessing the current behaviour (maybe some kind of allow_objects option?) so that the code can remain neater and not fiddle with individual columns (which is even more of a pain when writing utility function where the columns aren't known beforehand).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Deprecate Functionality to remove in pandas Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants