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 in `FrameApply.apply` when `result_type='broadcast'` is combined with `engine='numba'`. Broadcasting requires pandas to invoke the func per column and reshape the output to the original frame shape; this orchestration is not implemented for the numba engine, so pandas rejects it up front with NotImplementedError.
Solutions
- Drop `engine='numba'` when you need `result_type='broadcast'`.
- Drop `result_type='broadcast'` when you need numba, and reshape the output manually afterwards.
- Rewrite the UDF to return a same-length Series natively, eliminating the need for broadcast.
Example fix
// before df.apply(func, result_type='broadcast', engine='numba') // after df.apply(func, result_type='broadcast') # python engine
Defensive patterns
Strategy: validation
Validate before calling
def frame_apply_broadcast(df, func, result_type=None, engine='python'):
if result_type == 'broadcast' and engine == 'numba':
raise ValueError('numba engine does not support result_type=broadcast; drop one')
return df.apply(func, result_type=result_type, engine=engine) Type guard
def numba_engine_supports_result_type(result_type) -> bool:
return result_type != 'broadcast' Try / catch
try:
out = df.apply(func, result_type='broadcast', engine='numba')
except NotImplementedError as e:
if 'numba' in str(e).lower() and 'broadcast' in str(e).lower():
out = df.apply(func, result_type='broadcast') # python engine
else:
raise Prevention
- Pick one: either numba or result_type='broadcast', never both.
- Rewrite UDFs to return same-length Series natively to avoid broadcast entirely.
- Add a project-level lint that flags the combination.
When it happens
Trigger: `df.apply(func, result_type='broadcast', engine='numba')`. The check `self.result_type == 'broadcast'` triggers the guard.
Common situations: Users enable numba for speed and also request broadcasting for a UDF that returns scalars per row; combining two performance-oriented options without realizing they are incompatible.
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 using a numpy ufunc as…
- 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/4915527e12bfd874.
Report an issue: GitHub.
Appendix: 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 3b7651241d)