pandas-dev/pandas · error · NotImplementedError
the 'numba' engine doesn't support using a numpy ufunc as…
Error message
the 'numba' engine doesn't support using a numpy ufunc as the callable function
What it means
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.
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)`.
Example fix
// before df.apply(np.log, engine='numba') // after np.log(df) # or df.apply(np.log)
Defensive patterns
Strategy: validation
Validate before calling
import numpy as np
def frame_apply_ufunc_engine(df, func, engine='python'):
if engine == 'numba' and isinstance(func, np.ufunc):
# apply directly — ufuncs are vectorized already
return func(df)
return df.apply(func, engine=engine) Type guard
def numba_engine_supports_func_type(func) -> bool:
import numpy as np
return callable(func) and not isinstance(func, (str, np.ufunc)) Try / catch
try:
out = df.apply(func, engine='numba')
except NotImplementedError as e:
if 'numba' in str(e).lower() and 'ufunc' in str(e).lower():
out = func(df) # apply ufunc directly
else:
raise Prevention
- 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.
When it happens
Trigger: `df.apply(np.log, engine='numba')`, `df.apply(np.sqrt, engine='numba')`, or any `np.ufunc` instance with the numba engine.
Common situations: Users assume ufuncs (being numeric) are ideal for numba and pass them with `engine='numba'`; copy-paste of the engine flag.
Related errors
- The 'numba' engine doesn't support list-like/dict likes of…
- the 'numba' engine doesn't support lists of callables yet
- the 'numba' engine doesn't support result_type='broadcast'
- the 'numba' engine doesn't support using a string as the…
- axis other than 0 is not supported
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/2c0ac5dc71d6f0c1.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/apply.py:1036
return self.apply_list_or_dict_like()
# all empty
if len(self.columns) == 0 and len(self.index) == 0:
return self.apply_empty_result()
# string dispatch
if isinstance(self.func, str):
if self.engine == "numba":
raise NotImplementedError(
"the 'numba' engine doesn't support using "
"a string as the callable function"
)
return self.apply_str()
# ufunc
elif isinstance(self.func, np.ufunc):
if self.engine == "numba":
raise NotImplementedError(
"the 'numba' engine doesn't support "
"using a numpy ufunc as the callable function"
)
with np.errstate(all="ignore"):
results = self.obj._mgr.apply("apply", func=self.func)
# _constructor will retain self.index and self.columns
return self.obj._constructor_from_mgr(results, axes=results.axes)
# broadcasting
if self.result_type == "broadcast":
if self.engine == "numba":
raise NotImplementedError(
"the 'numba' engine doesn't support result_type='broadcast'"
)
return self.apply_broadcast(self.obj)
# one axis empty
elif not all(self.obj.shape):View on GitHub (pinned to 3b7651241d)