{"record":{"id":"4915527e12bfd874","repo":"pandas-dev/pandas","slug":"the-numba-engine-doesn-t-support-result-type-br","errorCode":null,"errorMessage":"the 'numba' engine doesn't support result_type='broadcast'","messagePattern":"the 'numba' engine doesn't support result_type='broadcast'","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":1048,"sourceCode":"                )\n            return self.apply_str()\n\n        # ufunc\n        elif isinstance(self.func, np.ufunc):\n            if self.engine == \"numba\":\n                raise NotImplementedError(\n                    \"the 'numba' engine doesn't support \"\n                    \"using a numpy ufunc as the callable function\"\n                )\n            with np.errstate(all=\"ignore\"):\n                results = self.obj._mgr.apply(\"apply\", func=self.func)\n            # _constructor will retain self.index and self.columns\n            return self.obj._constructor_from_mgr(results, axes=results.axes)\n\n        # broadcasting\n        if self.result_type == \"broadcast\":\n            if self.engine == \"numba\":\n                raise NotImplementedError(\n                    \"the 'numba' engine doesn't support result_type='broadcast'\"\n                )\n            return self.apply_broadcast(self.obj)\n\n        # one axis empty\n        elif not all(self.obj.shape):\n            return self.apply_empty_result()\n\n        # raw\n        elif self.raw:\n            return self.apply_raw(engine=self.engine, engine_kwargs=self.engine_kwargs)\n\n        return self.apply_standard()\n\n    def agg(self):\n        obj = self.obj\n        axis = self.axis\n","sourceCodeStart":1030,"sourceCodeEnd":1066,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/apply.py#L1030-L1066","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["Remove result_type='broadcast' (the numba engine does not support it).","If you need broadcast semantics, drop engine='numba' and keep result_type='broadcast' with the python engine.","Reformulate so func returns a scalar or 1-D array per column (the shape numba does support), then assemble the broadcast frame yourself afterward."],"exampleFix":"// before\ndf.apply(lambda c: c*2 + 1, result_type='broadcast', engine='numba')\n// after\ndf.apply(lambda c: c*2 + 1, result_type='broadcast')  # python engine\n// or restructure for numba\ndf.transform(lambda c: c*2+1, engine='numba')","handlingStrategy":"validation","validationCode":"if engine == 'numba' and result_type == 'broadcast':\n    raise ValueError(\"engine='numba' does not support result_type='broadcast'; pick one\")","typeGuard":"def compatible_broadcast_numba(engine: str, result_type):\n    return not (engine == 'numba' and result_type == 'broadcast')","tryCatchPattern":"try:\n    df.apply(func, result_type=result_type, engine=engine)\nexcept NotImplementedError as e:\n    if 'broadcast' in str(e):\n        df.apply(func, result_type=result_type)  # python engine\n    else:\n        raise","preventionTips":["Treat result_type='broadcast' as python-engine-only.","If you must broadcast under numba, restructure the function to return scalars or 1-D arrays."],"tags":["pandas","numba","apply","broadcast","engine"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}