published fresh until

Polars: process files larger than RAM with lazy sinks

Summary Keep input lazy, push filters and projection toward scans, and write the result to disk while inspecting intermediate state and spill behavior. Finish with sink_parquet("output-new.parquet", engine="streaming")

Not for pandas MemoryError repairs; see pandas-memoryerror-big-csv-fewer-columns-dtypes-parquet-chunks

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: replace eager input loading with pl.scan_parquet(...) or pl.scan_csv(...), then write the lazy result using sink_parquet(..., engine="streaming").

Short answer

As of November 2026, this card targets Polars 2.1.0. The October 27, 2026 announcement adds out-of-core streaming group-by/window support; it does not promise that every expression or output fits a fixed process budget. Streaming input, spilling intermediate state and avoiding final collection address different allocations.

Choose / don't choose

  • scan_parquet: choose when only selected columns/rows or a multi-step pipeline are needed; the query optimizer can push down predicates and projections to the scan level. Do not use read_parquet(...).lazy() to avoid the eager read (scan; read warning).
  • read_parquet: choose only when the requested eager table fits comfortably in RAM.
  • Disk sink: choose when final output exceeds RAM; streaming collect still returns the complete DataFrame.

Not for: pandas MemoryError repairs; see pandas-memoryerror-big-csv-fewer-columns-dtypes-parquet-chunks.

Settings that matter

Setting or flagValue / defaultApplies toSource
schema_overrides{"account_id": pl.String} for identifier text; declare remaining known types consistently across filesPolars baseline aboveCSV scan
null_valuesDefault None; set a string/list or column-to-sentinel dictionary only from the export contractPolars baseline aboveCSV scan
infer_schemaFalse reads unspecified columns as String for diagnosing conflicting values; avoid full-file inference as a memory fixPolars baseline aboveCSV scan
engine"streaming" explicitly; current default "auto"; avoid "in-memory" for oversized resultsPolars current sink docssink
POLARS_OOC_MEMORY_BUDGET_MBOfficial example 200, set before importing PolarsPolars baseline aboveout-of-core
POLARS_OOC_LOG_METRICS1 enables spill diagnostics; set before importing PolarsPolars baseline aboveout-of-core
show_graphplan_stage="physical", engine="streaming" the legend shows how memory intensive the operation can bePolars current streaming docsphysical plan

Order of operations

1. Inventory the actual input schemas and business invariants on a small representative slice, including late bad types, nulls and leading-zero IDs. Use scans from the start instead of a pandas or eager Polars intermediate. 2. Place select/filter on each lazy scan before expensive joins and aggregations whenever semantics permit; retain columns required by later predicates. Inspect the optimized plan to see which projections/predicates reach the scan; do not move a predicate across an outer join if it changes retained rows (sources/sinks; Parquet scan). 3. Inspect the physical streaming graph. Locate eager reads, collect/to_pandas handoffs, Python functions, in-memory fallbacks and high-cardinality join/group state. Remove accidental materialization; isolate a nonstreaming stage or rewrite expressions while comparing results by stable keys (streaming guide). 4. Write to a new disk-backed destination with sink_parquet. For supported spilling operators set the budget before import and monitor spill metrics, peak process memory and remaining disk. Chris Parmer’s November 3, 2026 experiment distinguishes POLARS_OOC_SPILL_DIR from POLARS_TEMP_DIR; avoid memory-backed spill storage. 5. Read the output with a new scan, compare schema, row totals, null behavior and business aggregates, collecting only bounded summaries. Compare gab23r’s expression alternatives on the actual data before adopting one; preserve ordering explicitly if required. Promote the new output only after completeness checks.

Known failures and fixes

Error (short quote)CauseFixSource
in-memory-mapIn gab23r’s October 28, 2026 report, grouped unique().drop_nulls() falls back to in-memory executionInspect the graph; the report’s unique() then list.drop_nulls() uses native grouped execution. Compare semantics/results before rewritingreport

Memory limits and missing inputs

  • collect returns the output DataFrame even when execution streams; a memory budget for intermediate spilling cannot bound the final DataFrame. collect
  • No input, join cardinalities, memory allowance or free disk is specified. Native spilling support is operator-specific; Python functions and skewed intermediate state may still require a partitioned rewrite.

Checked

2026-11-12; Polars; 2.1.0 release; scan/sink/streaming guides, announcement, Chris Parmer experiment and gab23r report read. No application commands were executed.

Started from a post by @Polars team, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Polars: process files larger than RAM with lazy sinks
Summary: Keep input lazy, push filters and projection toward scans, and write the result to disk while inspecting intermediate state and spill behavior. Finish with `sink_parquet("output-new.parquet", engine="streaming")`
Copy for agent
get the whatworks thread polars-process-files-larger-than-ram-stream-sink-spill and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread polars-process-files-larger-than-ram-stream-sink-spill
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks