{"record":{"id":"612fe6aa6af0d5c1","repo":"pandas-dev/pandas","slug":"column-colname-is-backed-by-an-extension-array","errorCode":null,"errorMessage":"Column {colname} is backed by an extension array, which is not supported by the numba engine.","messagePattern":"Column (.+?) is backed by an extension array, which is not supported by the numba engine\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":984,"sourceCode":"    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\n    def res_columns(self) -> Index:\n        return self.result_columns\n\n    @property\n    def columns(self) -> Index:","sourceCodeStart":966,"sourceCodeEnd":1002,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/apply.py#L966-L1002","documentation":"Raised by `validate_values_for_numba` when a column is backed by a pandas extension array (e.g. `Int64`, `Float64` nullable, `Categorical`, string dtype) even if its logical type is numeric. The numba engine requires plain numpy-backed arrays; extension arrays have a different memory layout and a mask, which numba cannot consume directly.","triggerScenarios":"`df.apply(func, engine='numba', raw=True)` where `df` uses nullable pandas dtypes (`'Int64'`, `'Float64'`), `pd.Categorical`, or the new string dtype. `is_extension_array_dtype` returns True and the check fires.","commonSituations":"Migrating to nullable dtypes for missing-value semantics then attempting numba acceleration; reading data via APIs that default to extension dtypes; mixing extension and numpy columns.","solutions":["Convert extension columns to plain numpy dtypes: `df = df.convert_dtypes(dtype_backend='numpy_nullable').astype({c: 'float64' for c in ext_cols})`, or `df[col].to_numpy(dtype='float64')`.","Drop or separate extension-array columns and use the python engine for them.","Use `astype('float64')` (with NaN handling for nullable ints) before invoking numba."],"exampleFix":"# before\ndf.astype('Int64').apply(func, engine='numba', raw=True)\n# after\ndf.astype('Int64').astype('float64').apply(func, engine='numba', raw=True)","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef apply_numba_numpy_only(df, func, **kw):\n    bad = [c for c in df.columns if pd.api.types.is_extension_array_dtype(df[c].dtype)]\n    if bad:\n        raise ValueError(f'extension-array columns unsupported by numba: {bad}')\n    return df.apply(func, engine='numba', raw=True, **kw)","typeGuard":"def no_extension_arrays(df) -> bool:\n    import pandas as pd\n    return not any(pd.api.types.is_extension_array_dtype(dt) for dt in df.dtypes)","tryCatchPattern":"try:\n    df.apply(func, engine='numba', raw=True)\nexcept ValueError as e:\n    if 'extension array' in str(e):\n        df.astype('float64').apply(func, engine='numba', raw=True)\n    else:\n        raise","preventionTips":["Convert nullable/extension dtypes to plain numpy dtypes before invoking numba.","Audit dtypes with `df.dtypes` when planning a numba apply."],"tags":["pandas","apply","numba","valueerror","extension-array","nullable"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}