pandas-dev/pandas · error · TypeError

Cannot interpolate with {self.dtype} dtype

Error message

Cannot interpolate with {self.dtype} dtype

What it means

Raised by NumpyExtensionArray.interpolate when self.dtype._is_numeric is False. Interpolation (linear, time, index, etc.) is mathematically defined only on numeric data, so non-numeric NumpyExtensionArrays (object, string, bool) reject it at the dtype check before any computation.

Source

Thrown at pandas/core/arrays/numpy_.py:398

    def interpolate(
        self,
        *,
        method: InterpolateOptions,
        axis: int,
        index: Index,
        limit,
        limit_direction,
        limit_area,
        copy: bool,
        **kwargs,
    ) -> Self:
        """
        See NDFrame.interpolate.__doc__.
        """
        # NB: we return type(self) even if copy=False
        if not self.dtype._is_numeric:
            raise TypeError(f"Cannot interpolate with {self.dtype} dtype")

        if not copy:
            out_data = self._ndarray
        else:
            out_data = self._ndarray.copy()

        # TODO: assert we have floating dtype?
        missing.interpolate_2d_inplace(
            out_data,
            method=method,
            axis=axis,
            index=index,
            limit=limit,
            limit_direction=limit_direction,
            limit_area=limit_area,
            **kwargs,
        )
        if not copy:

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Coerce the column to numeric first: s.astype('float64').interpolate().
  2. Use ffill/bfill (method='ffill'/'bfill') for non-numeric gaps; those go through _pad_or_backfill and do not require numeric dtype.
  3. Drop or replace NaN in object columns with fillna(value).

Example fix

# before
s = pd.Series(['1', '2', None, '4'], dtype='object')
s.interpolate()
# after
s = pd.to_numeric(s).interpolate()
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np
import pandas as pd

def can_interpolate(s: pd.Series) -> bool:
    arr = s.to_numpy() if hasattr(s, 'to_numpy') else np.asarray(s)
    if isinstance(s.dtype, pd.arrays.NumpyExtensionArray.dtype.__class__):
        return s.dtype._is_numeric if hasattr(s.dtype, '_is_numeric') else False
    return np.issubdtype(s.dtype, np.number)

Type guard

import numpy as np

def is_numeric_series(s) -> bool:
    return pd.api.types.is_numeric_dtype(s.dtype)

Try / catch

try:
    out = s.interpolate()
except TypeError:
    out = pd.to_numeric(s, errors='coerce').interpolate()

Prevention

When it happens

Trigger: Calling Series.interpolate() / DataFrame.interpolate() on an object-dtype or string-dtype column backed by NumpyExtensionArray. Calling .interpolate(method='linear') on a column of mixed-type or text values.

Common situations: Trying to fill missing string/object values with interpolate instead of ffill/bfill. Loading CSV data as object dtype then interpolating without first coercing to numeric.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/52fc959e254ad5e6. Report an issue: GitHub.