pandas-dev/pandas · error · NotImplementedError

the 'numba' engine doesn't support result_type='broadcast'

Error message

the 'numba' engine doesn't support result_type='broadcast'

What it means

Raised by DataFrame.apply when engine='numba' is combined with result_type='broadcast'. Broadcasting means the per-column function returns a value sized to fill the whole frame, a control-flow the numba code path does not implement (apply.py:1046-1050). The numba engine only supports the standard row/column-wise application that returns a scalar or same-shaped Series per chunk, so the broadcast variant is rejected explicitly.

Source

Thrown at pandas/core/apply.py:1048

                )
            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):
            return self.apply_empty_result()

        # raw
        elif self.raw:
            return self.apply_raw(engine=self.engine, engine_kwargs=self.engine_kwargs)

        return self.apply_standard()

    def agg(self):
        obj = self.obj
        axis = self.axis

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Remove result_type='broadcast' (the numba engine does not support it).
  2. If you need broadcast semantics, drop engine='numba' and keep result_type='broadcast' with the python engine.
  3. Reformulate so func returns a scalar or 1-D array per column (the shape numba does support), then assemble the broadcast frame yourself afterward.

Example fix

// before
df.apply(lambda c: c*2 + 1, result_type='broadcast', engine='numba')
// after
df.apply(lambda c: c*2 + 1, result_type='broadcast')  # python engine
// or restructure for numba
df.transform(lambda c: c*2+1, engine='numba')
Defensive patterns

Strategy: validation

Validate before calling

if engine == 'numba' and result_type == 'broadcast':
    raise ValueError("engine='numba' does not support result_type='broadcast'; pick one")

Type guard

def compatible_broadcast_numba(engine: str, result_type):
    return not (engine == 'numba' and result_type == 'broadcast')

Try / catch

try:
    df.apply(func, result_type=result_type, engine=engine)
except NotImplementedError as e:
    if 'broadcast' in str(e):
        df.apply(func, result_type=result_type)  # python engine
    else:
        raise

Prevention

When it happens

Trigger: df.apply(func, result_type='broadcast', engine='numba') where func is a callable. Hit in the broadcasting branch of NDFrame.apply at apply.py:1046-1050 whenever result_type is set to 'broadcast' while engine is 'numba'.

Common situations: Developers wanting a JIT-compiled function that emits full-length arrays per column; mixing API flags copied from python-engine examples with engine='numba'; assuming numba is a drop-in replacement that supports every result_type mode.

Related errors


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