{"record":{"id":"d9f73f72c8e0149f","repo":"pandas-dev/pandas","slug":"the-numba-engine-doesn-t-support-using-a-string","errorCode":null,"errorMessage":"the 'numba' engine doesn't support using a string as the callable function","messagePattern":"the 'numba' engine doesn't support using a string as the callable function","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":1027,"sourceCode":"    def apply(self) -> DataFrame | Series:\n        \"\"\"compute the results\"\"\"\n\n        # dispatch to handle list-like or dict-like\n        if is_list_like(self.func):\n            if self.engine == \"numba\":\n                raise NotImplementedError(\n                    \"the 'numba' engine doesn't support lists of callables yet\"\n                )\n            return self.apply_list_or_dict_like()\n\n        # all empty\n        if len(self.columns) == 0 and len(self.index) == 0:\n            return self.apply_empty_result()\n\n        # string dispatch\n        if isinstance(self.func, str):\n            if self.engine == \"numba\":\n                raise NotImplementedError(\n                    \"the 'numba' engine doesn't support using \"\n                    \"a string as the callable function\"\n                )\n            return self.apply_str()\n\n        # ufunc\n        elif isinstance(self.func, np.ufunc):\n            if self.engine == \"numba\":\n                raise NotImplementedError(\n                    \"the 'numba' engine doesn't support \"\n                    \"using a numpy ufunc as the callable function\"\n                )\n            with np.errstate(all=\"ignore\"):\n                results = self.obj._mgr.apply(\"apply\", func=self.func)\n            # _constructor will retain self.index and self.columns\n            return self.obj._constructor_from_mgr(results, axes=results.axes)\n\n        # broadcasting","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L1009-L1045","documentation":"Raised in `FrameApply.apply` string-dispatch branch when `self.func` is a `str` and `engine='numba'`. Numba requires a Python callable to JIT-compile; a method name string cannot be compiled, so pandas rejects it with NotImplementedError rather than resolving the string and silently falling back.","triggerScenarios":"`df.apply('mean', engine='numba')`, `df.apply('shift', engine='numba')`, or any string func with the numba engine.","commonSituations":"Users enable numba then pass a method name; copy-paste of engine setting from a callable-based apply into a string-based call.","solutions":["Drop `engine='numba'` for string funcs and use the default python engine.","Wrap the method in a callable: instead of `'mean'` use `lambda x: x.mean()` (or `np.mean`) with `engine='numba'`.","Prefer calling the method directly: `df.mean()` is faster than `df.apply('mean', engine='numba')` for built-in aggregations."],"exampleFix":"// before\ndf.apply('mean', engine='numba')\n// after\ndf.mean()  # or: df.apply(np.mean, engine='numba')","handlingStrategy":"validation","validationCode":"def frame_apply_str_engine(df, func, engine='python'):\n    if engine == 'numba' and isinstance(func, str):\n        raise ValueError('numba engine does not accept string funcs; pass a callable or drop engine')\n    return df.apply(func, engine=engine)","typeGuard":"def numba_engine_accepts(func) -> bool:\n    import numpy as np\n    return callable(func) and not isinstance(func, str) and not isinstance(func, np.ufunc)","tryCatchPattern":"try:\n    out = df.apply(func, engine='numba')\nexcept NotImplementedError as e:\n    if 'numba' in str(e).lower() and 'string' in str(e).lower():\n        out = df.apply(func)  # python engine\n    else:\n        raise","preventionTips":["Prefer calling built-in methods directly over apply-with-strings.","Wrap string funcs in callables before using numba.","Document the numba func-type contract in your project."],"tags":["pandas","apply","numba","string-dispatch","notimplementederror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}