pandas-dev/pandas · error · NotImplementedError

the 'numba' engine doesn't support using a string as the…

Error message

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

What it means

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.

Solutions

  1. Drop `engine='numba'` for string funcs and use the default python engine.
  2. Wrap the method in a callable: instead of `'mean'` use `lambda x: x.mean()` (or `np.mean`) with `engine='numba'`.
  3. Prefer calling the method directly: `df.mean()` is faster than `df.apply('mean', engine='numba')` for built-in aggregations.

Example fix

// before
df.apply('mean', engine='numba')
// after
df.mean()  # or: df.apply(np.mean, engine='numba')
Defensive patterns

Strategy: validation

Validate before calling

def frame_apply_str_engine(df, func, engine='python'):
    if engine == 'numba' and isinstance(func, str):
        raise ValueError('numba engine does not accept string funcs; pass a callable or drop engine')
    return df.apply(func, engine=engine)

Type guard

def numba_engine_accepts(func) -> bool:
    import numpy as np
    return callable(func) and not isinstance(func, str) and not isinstance(func, np.ufunc)

Try / catch

try:
    out = df.apply(func, engine='numba')
except NotImplementedError as e:
    if 'numba' in str(e).lower() and 'string' in str(e).lower():
        out = df.apply(func)  # python engine
    else:
        raise

Prevention

When it happens

Trigger: `df.apply('mean', engine='numba')`, `df.apply('shift', engine='numba')`, or any string func with the numba engine.

Common situations: Users enable numba then pass a method name; copy-paste of engine setting from a callable-based apply into a string-based call.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/d9f73f72c8e0149f. Report an issue: GitHub.

Appendix: source

Thrown at pandas/core/apply.py:1027

    def apply(self) -> DataFrame | Series:
        """compute the results"""

        # dispatch to handle list-like or dict-like
        if is_list_like(self.func):
            if self.engine == "numba":
                raise NotImplementedError(
                    "the 'numba' engine doesn't support lists of callables yet"
                )
            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

View on GitHub (pinned to 3b7651241d)