{"record":{"id":"2c0ac5dc71d6f0c1","repo":"pandas-dev/pandas","slug":"the-numba-engine-doesn-t-support-using-a-numpy-u","errorCode":null,"errorMessage":"the 'numba' engine doesn't support using a numpy ufunc as the callable function","messagePattern":"the 'numba' engine doesn't support using a numpy ufunc as the callable function","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":1036,"sourceCode":"            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\n        if self.result_type == \"broadcast\":\n            if self.engine == \"numba\":\n                raise NotImplementedError(\n                    \"the 'numba' engine doesn't support result_type='broadcast'\"\n                )\n            return self.apply_broadcast(self.obj)\n\n        # one axis empty\n        elif not all(self.obj.shape):","sourceCodeStart":1018,"sourceCodeEnd":1054,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L1018-L1054","documentation":"Raised in `FrameApply.apply` ufunc branch when `self.func` is a `numpy.ufunc` and `engine='numba'`. Although ufuncs are callable, pandas routes them through its internal manager path (`_mgr.apply('apply', ...)`) rather than the numba JIT path, so they are explicitly rejected with NotImplementedError.","triggerScenarios":"`df.apply(np.log, engine='numba')`, `df.apply(np.sqrt, engine='numba')`, or any `np.ufunc` instance with the numba engine.","commonSituations":"Users assume ufuncs (being numeric) are ideal for numba and pass them with `engine='numba'`; copy-paste of the engine flag.","solutions":["Drop `engine='numba'`; the python engine handles ufuncs efficiently via the manager path.","Wrap the ufunc in a Python callable for numba: `df.apply(lambda x: np.log(x), engine='numba')` (may or may not compile depending on numba version).","For simple elementwise math, call the ufunc directly: `np.log(df)`."],"exampleFix":"// before\ndf.apply(np.log, engine='numba')\n// after\nnp.log(df)  # or df.apply(np.log)","handlingStrategy":"validation","validationCode":"import numpy as np\ndef frame_apply_ufunc_engine(df, func, engine='python'):\n    if engine == 'numba' and isinstance(func, np.ufunc):\n        # apply directly — ufuncs are vectorized already\n        return func(df)\n    return df.apply(func, engine=engine)","typeGuard":"def numba_engine_supports_func_type(func) -> bool:\n    import numpy as np\n    return callable(func) and not isinstance(func, (str, np.ufunc))","tryCatchPattern":"try:\n    out = df.apply(func, engine='numba')\nexcept NotImplementedError as e:\n    if 'numba' in str(e).lower() and 'ufunc' in str(e).lower():\n        out = func(df)  # apply ufunc directly\n    else:\n        raise","preventionTips":["Apply numpy ufuncs directly to the frame (np.log(df)) instead of via apply.","Do not pair ufuncs with engine='numba'.","Document that numba needs pure-Python callables."],"tags":["pandas","apply","numba","ufunc","notimplementederror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}