{"record":{"id":"c29c30524a24fd60","repo":"pandas-dev/pandas","slug":"parallel-apply-is-not-supported-when-raw-false-and","errorCode":null,"errorMessage":"Parallel apply is not supported when raw=False and engine='numba'","messagePattern":"Parallel apply is not supported when raw=False and engine='numba'","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/apply.py","lineNumber":1307,"sourceCode":"        assert callable(self.func)\n\n        series_gen = self.series_generator\n        res_index = self.result_index\n\n        results = {}\n\n        for i, v in enumerate(series_gen):\n            results[i] = self.func(v, *self.args, **self.kwargs)\n            if isinstance(results[i], ABCSeries):\n                # If we have a view on v, we need to make a copy because\n                #  series_generator will swap out the underlying data\n                results[i] = results[i].copy(deep=False)\n\n        return results, res_index\n\n    def apply_series_numba(self):\n        if self.engine_kwargs.get(\"parallel\", False):\n            raise NotImplementedError(\n                \"Parallel apply is not supported when raw=False and engine='numba'\"\n            )\n        if not self.obj.index.is_unique or not self.columns.is_unique:\n            raise NotImplementedError(\n                \"The index/columns must be unique when raw=False and engine='numba'\"\n            )\n        self.validate_values_for_numba()\n        results = self.apply_with_numba()\n        return results, self.result_index\n\n    def wrap_results(self, results: ResType, res_index: Index) -> DataFrame | Series:\n        from pandas import Series\n\n        # see if we can infer the results\n        if len(results) > 0 and 0 in results and is_sequence(results[0]):\n            return self.wrap_results_for_axis(results, res_index)\n\n        # dict of scalars","sourceCodeStart":1289,"sourceCodeEnd":1325,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/apply.py#L1289-L1325","documentation":"Raised by apply_series_numba when engine='numba' is used with raw=False (the default, where the function receives a Series per row) and engine_kwargs contains {'parallel': True}. The numba backend's Series-based apply path has no parallel implementation, so pandas refuses to run rather than silently ignoring the parallel flag.","triggerScenarios":"df.apply(func, engine='numba', engine_kwargs={'parallel': True}) where func expects a Series; Series.apply(func, engine='numba', engine_kwargs={'parallel': True}).","commonSituations":"Developers switch on numba expecting speed and additionally enable parallel=True (copied from a tutorial or numba.jit example) without realizing the Series apply path is single-threaded only.","solutions":["Remove 'parallel' from engine_kwargs (default engine_kwargs={}, single-threaded numba).","If parallel execution is required, switch to engine='numba' with raw=True so the function receives numpy values and the parallel numba path applies.","Drop numba and use the default python engine, which supports the existing Series func unchanged."],"exampleFix":"# before\ndf.apply(func, engine='numba', engine_kwargs={'parallel': True})\n# after\ndf.apply(func, engine='numba')","handlingStrategy":"validation","validationCode":"def safe_numba_apply(obj, func, **kwargs):\n    ek = kwargs.get('engine_kwargs') or {}\n    if kwargs.get('engine') == 'numba' and ek.get('parallel', False):\n        raise ValueError(\"parallel=True is not supported with engine='numba' and raw=False; dropping parallel\")\n    return obj.apply(func, **kwargs)","typeGuard":null,"tryCatchPattern":"try:\n    df.apply(func, engine='numba', engine_kwargs=ek)\nexcept NotImplementedError as e:\n    if 'Parallel apply' in str(e):\n        df.apply(func, engine='numba')  # fall back to single-threaded numba\n    else:\n        raise","preventionTips":["Default engine_kwargs to {} and only set parallel=True when also setting raw=True.","Document in code review that numba Series-apply is single-threaded only."],"tags":["numba","apply","performance","engine"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}