Skip to content

API/DEPR: interpolate with object dtype #53631

Closed
@jbrockmendel

Description

@jbrockmendel
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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDeprecateFunctionality to remove in pandasMissing-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