{"record":{"id":"4080584180179406","repo":"pola-rs/polars","slug":"collect-batches-is-not-supported-by-type-self","errorCode":null,"errorMessage":"`collect_batches` is not supported by {type(self).__name__}","messagePattern":"`collect_batches` is not supported by (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/engine.py","lineNumber":164,"sourceCode":"        optimizations: QueryOptFlags,\n        gevent: bool = False,\n    ) -> AsyncResult[DataFrame]:\n        \"\"\"Execute `lf` asynchronously.\"\"\"\n        msg = f\"`collect_async` is not supported by {type(self).__name__}\"\n        raise NotImplementedError(msg)\n\n    def collect_batches(\n        self,\n        lf: LazyFrame,\n        *,\n        optimizations: QueryOptFlags,\n        maintain_order: bool = True,\n        chunk_size: int | None = None,\n        lazy: bool = False,\n    ) -> _CollectBatches:\n        \"\"\"Execute `lf`, yielding its result in batches.\"\"\"\n        msg = f\"`collect_batches` is not supported by {type(self).__name__}\"\n        raise NotImplementedError(msg)\n\n    def collect_all(\n        self, lfs: Iterable[LazyFrame], *, optimizations: QueryOptFlags\n    ) -> list[DataFrame]:\n        \"\"\"Execute several queries, potentially in parallel.\"\"\"\n        msg = f\"`collect_all` is not supported by {type(self).__name__}\"\n        raise NotImplementedError(msg)\n\n    def collect_all_async(\n        self,\n        lfs: Iterable[LazyFrame],\n        *,\n        optimizations: QueryOptFlags,\n        gevent: bool = False,\n    ) -> AsyncResult[list[DataFrame]]:\n        \"\"\"Execute several queries asynchronously.\"\"\"\n        msg = f\"`collect_all_async` is not supported by {type(self).__name__}\"\n        raise NotImplementedError(msg)","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/lazyframe/engine.py#L146-L182","documentation":"`collect_batches` executes a LazyFrame and yields results in batches; only some engines implement it. The base `Engine` class raises NotImplementedError with this message when the selected engine does not provide batched collection.","triggerScenarios":"Calling `LazyFrame.collect_batches(engine=<engine>)` where the engine class does not override `collect_batches` — e.g. a custom engine or an engine whose base-class stub is reached.","commonSituations":"Custom Engine implementations missing the batched-collect override; passing an engine alias that maps to a non-batching engine; code copied from streaming examples executed against another engine.","solutions":["Use `lf.collect_batches()` with the default/local engine that implements batching.","If batching is not essential, call `lf.collect()` and slice the DataFrame into chunks yourself.","Implement `collect_batches` in your custom Engine subclass, returning a `_CollectBatches` iterator.","Verify the engine parameter value against polars docs for batched-execution support."],"exampleFix":"// before\nfor df in lf.collect_batches(engine=\"custom-engine\"): ...\n// after\nfor df in lf.collect_batches(): ...  # default engine supports batching","handlingStrategy":"try-catch","validationCode":"if type(engine_obj).collect_batches is Engine.collect_batches:\n    use_default_engine = True","typeGuard":"def supports_batches(engine: object) -> bool:\n    return type(engine).collect_batches is not Engine.collect_batches","tryCatchPattern":"try:\n    it = lf.collect_batches(engine=eng)\nexcept NotImplementedError:\n    df = lf.collect()","preventionTips":["Prefer the default engine for batched collection","Implement collect_batches when subclassing Engine","Add capability checks before batch APIs"],"tags":["python","polars","streaming","not-implemented"],"backgroundTag":"method-not-implemented","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}