{"record":{"id":"52fc959e254ad5e6","repo":"pandas-dev/pandas","slug":"cannot-interpolate-with-self-dtype-dtype-52fc95","errorCode":null,"errorMessage":"Cannot interpolate with {self.dtype} dtype","messagePattern":"Cannot interpolate with (.+?) dtype","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/numpy_.py","lineNumber":398,"sourceCode":"\n    def interpolate(\n        self,\n        *,\n        method: InterpolateOptions,\n        axis: int,\n        index: Index,\n        limit,\n        limit_direction,\n        limit_area,\n        copy: bool,\n        **kwargs,\n    ) -> Self:\n        \"\"\"\n        See NDFrame.interpolate.__doc__.\n        \"\"\"\n        # NB: we return type(self) even if copy=False\n        if not self.dtype._is_numeric:\n            raise TypeError(f\"Cannot interpolate with {self.dtype} dtype\")\n\n        if not copy:\n            out_data = self._ndarray\n        else:\n            out_data = self._ndarray.copy()\n\n        # TODO: assert we have floating dtype?\n        missing.interpolate_2d_inplace(\n            out_data,\n            method=method,\n            axis=axis,\n            index=index,\n            limit=limit,\n            limit_direction=limit_direction,\n            limit_area=limit_area,\n            **kwargs,\n        )\n        if not copy:","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/numpy_.py#L380-L416","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Coerce the column to numeric first: s.astype('float64').interpolate().","Use ffill/bfill (method='ffill'/'bfill') for non-numeric gaps; those go through _pad_or_backfill and do not require numeric dtype.","Drop or replace NaN in object columns with fillna(value)."],"exampleFix":"# before\ns = pd.Series(['1', '2', None, '4'], dtype='object')\ns.interpolate()\n# after\ns = pd.to_numeric(s).interpolate()","handlingStrategy":"validation","validationCode":"import numpy as np\nimport pandas as pd\n\ndef can_interpolate(s: pd.Series) -> bool:\n    arr = s.to_numpy() if hasattr(s, 'to_numpy') else np.asarray(s)\n    if isinstance(s.dtype, pd.arrays.NumpyExtensionArray.dtype.__class__):\n        return s.dtype._is_numeric if hasattr(s.dtype, '_is_numeric') else False\n    return np.issubdtype(s.dtype, np.number)","typeGuard":"import numpy as np\n\ndef is_numeric_series(s) -> bool:\n    return pd.api.types.is_numeric_dtype(s.dtype)","tryCatchPattern":"try:\n    out = s.interpolate()\nexcept TypeError:\n    out = pd.to_numeric(s, errors='coerce').interpolate()","preventionTips":["Standardize numeric columns to numeric dtypes at load time.","Reserve interpolate() for numeric data; use ffill/bfill for categorical/text.","Check pd.api.types.is_numeric_dtype before interpolating dynamic schemas."],"tags":["interpolate","dtype","numeric","pandas-arrays"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}