pandas-dev/pandas · error · TypeError
Cannot interpolate with
Error message
Cannot interpolate with {self.dtype} dtype What it means
interpolate() requires numeric data: the method's math (pairwise_diff, divide_checked, or the missing.interpolate_2d_inplace fallback) is undefined for non-numeric dtypes. The guard at the top refuses any dtype whose _is_numeric is False, raising TypeError with the offending dtype.
Solutions
- Use .fillna(method='ffill')/.ffill() for non-numeric columns instead of .interpolate().
- Select only numeric columns: df.select_dtypes(include='number').interpolate().
- Cast the column to a numeric dtype if it actually contains numbers stored as strings.
Example fix
// before s = pd.Series(["1", None, "3"], dtype="string[pyarrow]") s.interpolate() // after s = pd.Series([1.0, None, 3.0], dtype="double[pyarrow]") s.interpolate()
Defensive patterns
Strategy: validation
Validate before calling
def safe_interpolate(s, **kw):
if not getattr(s.dtype, "_is_numeric", False):
raise TypeError(f"interpolate needs numeric dtype, got {s.dtype}")
return s.interpolate(**kw) Type guard
def is_numeric_dtype_obj(dtype) -> bool:
return bool(getattr(dtype, "_is_numeric", False)) Try / catch
try:
s.interpolate()
except TypeError:
s.ffill() # non-numeric fallback Prevention
- Run interpolate only on numeric columns.
- Use ffill/bfill for non-numeric gap filling.
When it happens
Trigger: Calling .interpolate() on a string[pyarrow], binary[pyarrow], bool[pyarrow], or categorical-backed-by-arrow Series.
Common situations: Applying interpolate() to a whole DataFrame containing string columns; expecting interpolate to forward-fill text data.
Related errors
- dtype ' ' does not support operation
- interpolate is not implemented for dtype=
- operation ' ' not supported for dtype
- ' ' with dtype does not support operation
- ambiguous is not supported.
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/e9049fb46c19a5f9.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/arrow/array.py:3177
def interpolate(
self,
*,
method: InterpolateOptions,
axis: int,
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 (
method == "linear"
and limit_area is None
and limit is None
and limit_direction == "forward"
):
values = self._pa_array.combine_chunks()
na_value = pa.array([None], type=values.type)
y_diff_2 = pc.fill_null_backward(pc.pairwise_diff_checked(values, period=2))
prev_values = pa.concat_arrays([na_value, values[:-2], na_value])
interps = pc.add_checked(prev_values, pc.divide_checked(y_diff_2, 2))
return self._from_pyarrow_array(pc.coalesce(self._pa_array, interps))
mask = self.isna()
if self.dtype.kind == "f":
data = self._pa_array.to_numpy()
elif self.dtype.kind in "iu":View on GitHub (pinned to 3b7651241d)