{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L1030-L1066","documentation":"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.","triggerScenarios":"`df.apply(func, result_type='broadcast', engine='numba')`. The check `self.result_type == 'broadcast'` triggers the guard.","commonSituations":"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.","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."],"exampleFix":"// before\ndf.apply(func, result_type='broadcast', engine='numba')\n// after\ndf.apply(func, result_type='broadcast')  # python engine","handlingStrategy":"validation","validationCode":"def frame_apply_broadcast(df, func, result_type=None, engine='python'):\n    if result_type == 'broadcast' and engine == 'numba':\n        raise ValueError('numba engine does not support result_type=broadcast; drop one')\n    return df.apply(func, result_type=result_type, engine=engine)","typeGuard":"def numba_engine_supports_result_type(result_type) -> bool:\n    return result_type != 'broadcast'","tryCatchPattern":"try:\n    out = df.apply(func, result_type='broadcast', engine='numba')\nexcept NotImplementedError as e:\n    if 'numba' in str(e).lower() and 'broadcast' in str(e).lower():\n        out = df.apply(func, result_type='broadcast')  # python engine\n    else:\n        raise","preventionTips":["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."],"tags":["pandas","apply","numba","broadcast","notimplementederror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}