{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/apply.py#L1009-L1045","documentation":"Raised in `FrameApply.apply` when `func` is a string AND `engine='numba'`. The numba engine needs a Python callable to JIT-compile; a method-name string cannot be compiled by numba. The check at apply.py:1026 fires before string dispatch is attempted.","triggerScenarios":"`df.apply('sum', engine='numba')` or `df.apply('mean', engine='numba')`. Any string-named method combined with `engine='numba'` triggers it.","commonSituations":"Trying to speed up named aggregations with numba; copy-pasting `engine='numba'` into code that uses string method dispatch; assuming numba understands pandas method names.","solutions":["Drop `engine='numba'` for string-dispatched methods (use the default engine).","Resolve the string to a callable first if you need numba, e.g. `df.apply(np.sum, engine='numba', raw=True)`.","Use `df.sum()` directly for built-in aggregations — these are already optimized."],"exampleFix":"# before\ndf.apply('sum', engine='numba')\n# after\ndf.sum()  # or\ndf.apply(np.sum, engine='numba', raw=True)","handlingStrategy":"validation","validationCode":"def safe_apply_numba(df, func, engine='python', **kw):\n    if engine == 'numba' and isinstance(func, str):\n        raise ValueError('numba engine does not support string function names')\n    return df.apply(func, engine=engine, **kw)","typeGuard":"def is_numba_compatible_func(func, engine) -> bool:\n    return engine != 'numba' or (callable(func) and not isinstance(func, str))","tryCatchPattern":"try:\n    df.apply(func_name, engine='numba')\nexcept NotImplementedError as e:\n    if 'string as the callable' in str(e):\n        import numpy as np\n        df.apply(getattr(np, func_name), engine='numba', raw=True)\n    else:\n        raise","preventionTips":["Do not pass string method names with engine='numba'; resolve to a callable first.","Prefer `df.sum()` directly for built-in named aggregations."],"tags":["pandas","apply","numba","notimplementederror","string-dispatch"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}