{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/apply.py#L1289-L1325","documentation":"Raised by apply_series_numba (apply.py:1307) when engine='numba' is used with raw=False and the user requested parallel=True via engine_kwargs. Parallel numba apply is only supported on the raw=True path (where each chunk is a numpy array); the Series-passing numba path cannot safely share work across threads, so pandas rejects the combination explicitly.","triggerScenarios":"df.apply(func, engine='numba', engine_kwargs={'parallel': True}) with the default raw=False. Hit at apply.py:1306-1309 in apply_series_numba when engine_kwargs.get('parallel', False) is truthy.","commonSituations":"Copying a parallel-numba example that was written for raw=True; passing engine_kwargs from a config without checking the raw mode; assuming parallel works regardless of whether Series or ndarray is passed.","solutions":["Drop parallel=True from engine_kwargs when using raw=False with engine='numba'.","If you need parallel numba, add raw=True so each call receives an ndarray: df.apply(func, raw=True, engine='numba', engine_kwargs={'parallel': True}).","Keep parallel=False (default) and rely on numba's single-threaded JIT, or parallelize at a higher level with multiprocessing/concurrent.futures."],"exampleFix":"// before\ndf.apply(func, engine='numba', engine_kwargs={'parallel': True})\n// after\ndf.apply(func, raw=True, engine='numba', engine_kwargs={'parallel': True})","handlingStrategy":"validation","validationCode":"parallel = (engine_kwargs or {}).get('parallel', False)\nif engine == 'numba' and parallel and not raw:\n    raise ValueError(\"parallel=True with engine='numba' requires raw=True\")","typeGuard":"def numba_parallel_ok(engine: str, raw: bool, engine_kwargs: dict) -> bool:\n    return not (engine == 'numba' and (engine_kwargs or {}).get('parallel') and not raw)","tryCatchPattern":"try:\n    df.apply(func, engine='numba', engine_kwargs=engine_kwargs, raw=raw)\nexcept NotImplementedError as e:\n    if 'Parallel apply' in str(e):\n        df.apply(func, engine='numba', raw=True, engine_kwargs=engine_kwargs)\n    else:\n        raise","preventionTips":["Pair parallel=True with raw=True whenever engine='numba'.","Keep engine_kwargs in a single config dict and validate against raw at construction time."],"tags":["pandas","numba","apply","parallel","engine"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}