pandas-dev/pandas · error · NotImplementedError

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

Error message

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

What it means

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.

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

Solutions

  1. Drop `engine='numba'` for string-dispatched methods (use the default engine).
  2. Resolve the string to a callable first if you need numba, e.g. `df.apply(np.sum, engine='numba', raw=True)`.
  3. Use `df.sum()` directly for built-in aggregations — these are already optimized.

Example fix

# before
df.apply('sum', engine='numba')
# after
df.sum()  # or
df.apply(np.sum, engine='numba', raw=True)
Defensive patterns

Strategy: validation

Validate before calling

def safe_apply_numba(df, func, engine='python', **kw):
    if engine == 'numba' and isinstance(func, str):
        raise ValueError('numba engine does not support string function names')
    return df.apply(func, engine=engine, **kw)

Type guard

def is_numba_compatible_func(func, engine) -> bool:
    return engine != 'numba' or (callable(func) and not isinstance(func, str))

Try / catch

try:
    df.apply(func_name, engine='numba')
except NotImplementedError as e:
    if 'string as the callable' in str(e):
        import numpy as np
        df.apply(getattr(np, func_name), engine='numba', raw=True)
    else:
        raise

Prevention

When it happens

Trigger: `df.apply('sum', engine='numba')` or `df.apply('mean', engine='numba')`. Any string-named method combined with `engine='numba'` triggers it.

Common situations: 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.

Related errors


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