{"record":{"id":"ddd5498b31fb8d6c","repo":"pola-rs/polars","slug":"collect-async-is-not-supported-by-type-self","errorCode":null,"errorMessage":"`collect_async` is not supported by {type(self).__name__}","messagePattern":"`collect_async` is not supported by (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/engine.py","lineNumber":151,"sourceCode":"\n        This method of materializing a `LazyFrame` makes no guarantees as to where\n        the result is materialized. This can be on the GPU for the GPU-engine,\n        on the cluster or remote storage for the distributed engine and the streaming\n        engine could spill the result if it needed to.\n\n        The `QueryResult` can always be consumed as a new `LazyFrame` by calling `.lazy`\n        \"\"\"\n\n    def collect_async(\n        self,\n        lf: LazyFrame,\n        *,\n        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.\"\"\"","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/lazyframe/engine.py#L133-L169","documentation":"`collect_async` is part of the `Engine` interface in polars' lazyframe engine module. The default/base engine implementation raises NotImplementedError because asynchronous execution is only provided by engines that support it (e.g. in-process async-capable engines or the streaming remote engine). Calling it on an engine lacking async support produces this error.","triggerScenarios":"Calling `LazyFrame.collect_async(engine=...)` (or `lf.collect_async()` via `CollectEngine`) with an engine class that does not override `collect_async`, e.g. a custom/user-defined engine or one whose base implementation was hit.","commonSituations":"Implementing a custom `Engine` subclass without overriding `collect_async`; passing an engine name that resolves to a base-class engine; code copied from async examples run with a different engine selection.","solutions":["Use a supported engine, e.g. `lf.collect(engine='in-memory')` or use `collect_async` with an engine that implements it (the async-capable in-process engine).","Replace `collect_async` with synchronous `lf.collect(optimizations=...)` in a thread if you only need non-blocking behavior.","If you wrote a custom Engine, implement `collect_async` to return an `AsyncResult` for your backend.","Check `isinstance(engine, ...)`/docs to confirm which async operations your engine supports."],"exampleFix":"// before\nawait lf.collect_async(engine=\"streaming\")  # engine lacks collect_async\n// after\ndf = lf.collect(engine=\"in-memory\")","handlingStrategy":"try-catch","validationCode":"if not hasattr(type(engine_obj), \"collect_async\") or type(engine_obj).collect_async is Engine.collect_async:\n    # fall back to sync collect","typeGuard":"def supports_async(engine: object) -> bool:\n    return type(engine).collect_async is not Engine.collect_async","tryCatchPattern":"try:\n    result = lf.collect_async(engine=eng)\nexcept NotImplementedError:\n    result = lf.collect(engine=\"in-memory\")","preventionTips":["Use built-in engines rather than custom subclasses unless async is implemented","Check polars docs for engine capability matrix","Wrap async APIs with NotImplementedError fallbacks"],"tags":["python","polars","async","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"}