Materialize lazy results
Run a deferred transformation pipeline and obtain a concrete DataFrame for analysis or output.
Polars · Module
Executes a LazyFrame query and materializes its result as a DataFrame. It supports configurable engines, optimization controls, streaming execution, and optional background execution.
Call collect on a LazyFrame to execute its deferred query plan and produce a concrete result. The method can use different execution engines, run in the background, and accept optimization settings; streaming execution processes the query in batches to reduce memory pressure.
LazyFrame.collect(*, engine: EngineType = 'auto', background: bool = False, optimizations: QueryOptFlags = (), **_kwargs: Any) → DataFrame | InProcessQuery| Name | Type | Description |
|---|---|---|
engine | EngineType = 'auto' | Execution engine to use; defaults to "auto". Supported names include "auto", "in-memory", "streaming", and "gpu". |
background | bool = False | Run asynchronously in the background and return an in-process query handle. |
optimizations | QueryOptFlags = () | Query optimization flags controlling enabled optimizations. |
_kwargs | Any | Additional keyword arguments accepted by the method. |
DataFrame when executed normally; an InProcessQuery handle when background=True.
collect turns deferred LazyFrame operations into an eagerly available DataFrame.engine parameter controls which execution backend processes the query.background=True, the return value is a query handle rather than the completed DataFrame.import polars as pl
lf = pl.LazyFrame({"value": [1, 2, 3]})
result = (
lf.filter(pl.col("value") > 1)
.select((pl.col("value") * 10).alias("scaled"))
.collect()
)
print(result)Builds a lazy query, then materializes its optimized result as a DataFrame.
Run a deferred transformation pipeline and obtain a concrete DataFrame for analysis or output.
Process queries in batches when the in-memory execution path creates excessive memory pressure.
Start a long-running query without blocking the calling workflow.
LazyFrame.collect do?collect materializes a LazyFrame into a DataFrame. Lazy operations remain deferred until this call, allowing Polars to optimize the query before execution.
Follow-up: How would you lower memory pressure? Use engine="streaming", which executes the query in batches.
collect use?The default engine is "auto". Other documented choices include "in-memory", "streaming", and "gpu"; the GPU engine requires an Nvidia GPU and cudf-polars.
Follow-up: When is the GPU engine unsuitable? It is unsuitable when the required CUDA and cuDF-based Polars setup is unavailable.
By default, query optimizations are enabled. The optimizations argument lets callers disable individual optimizations through query optimization flags.
Follow-up: How can the evaluated plan be inspected? Use the related explain method to print the query plan evaluated by collect.
polars.LazyFrame.explainpolars.LazyFrame.profilepolars.collect_allpolars.LazyFrame.collect_async