pandas-dev/pandas · error · NotImplementedError

the 'numba' engine doesn't support using a numpy ufunc as th

Error message

the 'numba' engine doesn't support using a numpy ufunc as the callable function

What it means

Raised by DataFrame.apply / Series.apply when the user passes engine='numba' alongside a numpy ufunc (e.g. np.add, np.sqrt) as the func argument. The numba code path only JIT-compiles user-supplied Python callables; numpy ufuncs are C-level functions that numba cannot trace, so the combination is rejected up front in pandas/core/apply.py:1036. The error is a NotImplementedError, signaling that the feature is intentionally unsupported rather than buggy.

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 71959b8cb9)

Solutions

  1. Drop engine='numba' if you must use a numpy ufunc: df.apply(np.negative) (default 'python' engine handles ufuncs natively).
  2. If you need numba speedups, write a @njit Python function and pass that as func instead of the numpy ufunc.
  3. For elementwise ufunc math on a DataFrame, skip apply entirely and call the ufunc directly: np.negative(df) or df * -1, which dispatches via __array_ufunc__.

Example fix

// before
df.apply(np.negative, engine='numba')
// after
df.apply(np.negative)  # uses python engine, ufunc fast-path
// or
import numba
@numba.njit
def neg(x):
    return -x
df.apply(neg, engine='numba', raw=True)
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np
if engine == 'numba' and isinstance(func, np.ufunc):
    raise ValueError('numpy ufuncs are unsupported with engine=numba; use a @njit function or drop engine=numba')

Type guard

def is_numba_safe_func(func, engine: str) -> bool:
    import numpy as np
    if engine != 'numba':
        return True
    return not isinstance(func, np.ufunc) and not isinstance(func, str)

Try / catch

try:
    df.apply(func, engine=engine)
except NotImplementedError as e:
    if "numba" in str(e) and "ufunc" in str(e):
        df.apply(func)  # fall back to python engine
    else:
        raise

Prevention

When it happens

Trigger: Calling df.apply(np.negative, engine='numba'), df.apply(np.add, engine='numba'), or any df.apply(...)/s.apply(...) where func is an instance of np.ufunc and engine='numba' is also passed (with raw=False). Triggered in the NDFrame.apply path at apply.py:1034-1039.

Common situations: Developers migrating a hot loop to numba for speed and assuming any numpy function works; passing np.<something> as a shortcut instead of writing a @numba.njit-decorated function; copying examples from non-numba code into an engine='numba' call.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/2c0ac5dc71d6f0c1. Report an issue: GitHub.