{"record":{"id":"efcc50ca0bd23808","repo":"pandas-dev/pandas","slug":"column-colname-must-have-a-numeric-dtype-found","errorCode":null,"errorMessage":"Column {colname} must have a numeric dtype. Found '{dtype}' instead","messagePattern":"Column (.+?) must have a numeric dtype\\. Found '(.+?)' instead","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":979,"sourceCode":"        pass\n\n    @staticmethod\n    @functools.cache\n    @abc.abstractmethod\n    def generate_numba_apply_func(\n        func, nogil: bool = True, parallel: bool = False\n    ) -> Callable[[npt.NDArray, Index, Index], dict[int, Any]]:\n        pass\n\n    @abc.abstractmethod\n    def apply_with_numba(self):\n        pass\n\n    def validate_values_for_numba(self) -> None:\n        # Validate column dtypes all OK\n        for colname, dtype in self.obj.dtypes.items():\n            if not is_numeric_dtype(dtype):\n                raise ValueError(\n                    f\"Column {colname} must have a numeric dtype. \"\n                    f\"Found '{dtype}' instead\"\n                )\n            if is_extension_array_dtype(dtype):\n                raise ValueError(\n                    f\"Column {colname} is backed by an extension array, \"\n                    f\"which is not supported by the numba engine.\"\n                )\n\n    @abc.abstractmethod\n    def wrap_results_for_axis(\n        self, results: ResType, res_index: Index\n    ) -> DataFrame | Series:\n        pass\n\n    # ---------------------------------------------------------------\n\n    @property","sourceCodeStart":961,"sourceCodeEnd":997,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L961-L997","documentation":"Raised by `validate_values_for_numba` when a column of the DataFrame being passed to the numba engine has a non-numeric dtype (e.g. object, string, datetime, category). Numba JIT-compiles per-column numeric kernels and cannot handle arbitrary Python objects, so pandas validates every column dtype before invoking numba and reports the offending column and dtype.","triggerScenarios":"`df.apply(func, engine='numba')` where `df` contains any non-numeric column (object, str, datetime64, category, bool-on some versions). The loop iterates `self.obj.dtypes.items()`.","commonSituations":"Mixed-type frames where an index or stray string column prevents numba compilation; CSVs that import numeric-looking columns as object due to NaNs/strings; datetime indexes that get included as columns after a reset_index.","solutions":["Select only numeric columns before applying: `df.select_dtypes('number').apply(func, engine='numba')`.","Coerce dtypes upstream: `df[col] = pd.to_numeric(df[col], errors='coerce')`.","Drop or separate datetime/string columns and process them with the python engine."],"exampleFix":"// before\ndf.apply(func, engine='numba')  # df has an object column\n// after\ndf.select_dtypes('number').apply(func, engine='numba')","handlingStrategy":"validation","validationCode":"def numeric_only_numba_apply(df, func, **kw):\n    non_numeric = [c for c, d in df.dtypes.items() if not pd.api.types.is_numeric_dtype(d)]\n    if non_numeric:\n        raise ValueError(f'Non-numeric columns block numba: {non_numeric}')\n    return df.apply(func, engine='numba', **kw)","typeGuard":"def frame_is_numeric(df) -> bool:\n    return all(pd.api.types.is_numeric_dtype(d) for d in df.dtypes)","tryCatchPattern":"try:\n    out = df.apply(func, engine='numba')\nexcept ValueError as e:\n    if 'numeric dtype' in str(e):\n        out = df.select_dtypes('number').apply(func, engine='numba')\n    else:\n        raise","preventionTips":["Call df.select_dtypes('number') before numba apply.","Coerce dtypes at ingestion time with pd.to_numeric.","Log dtypes before performance-critical apply paths."],"tags":["pandas","apply","numba","dtype","valueerror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}