Skip to content

Guides

Loading data

A frame that a reader gives is typed when the call names its schema. Without a schema, Polars finds the data types from the data when the code runs, and the checker cannot know them.

The readers and the constructors that take schema= give a typed frame. A scan_* reader gives a typed lazy frame:

load.pymypy: no errors
1import polars as pl
2
3lazy = pl.scan_csv("trades.csv", schema={"symbol": pl.String, "price": pl.Float64})
4rows = pl.from_dicts(
5 [{"symbol": "A", "price": 1.0}], schema={"symbol": pl.String, "price": pl.Float64}
6)
Resultlazydeclared
symbolStringpriceFloat64
Revealed type
TypedLazyFrame[TypedDict({'symbol': String, 'price': Float64}, closed=True), None]
Resultrowsdeclared
symbolStringpriceFloat64
Revealed type
TypedDataFrame[TypedDict({'symbol': String, 'price': Float64}, closed=True), None]

These calls read a schema: pl.read_csv, pl.scan_csv, pl.read_parquet, pl.scan_parquet, pl.read_json, pl.read_ndjson, pl.scan_ndjson, pl.from_dict, pl.from_dicts, pl.from_records and pl.from_numpy.

The checker reads a dict literal in the call. It does not follow a dict that a variable holds, so the frame stays plain:

load.pymypy: no errors
1import polars as pl
2
3schema = {"symbol": pl.String, "price": pl.Float64}
4trades = pl.read_csv("trades.csv", schema=schema)
Resulttrades
DataFrame

To use one schema in several places, declare a Columns class, and check each frame at the boundary with check_schema. See Runtime checks.

A plain frame has no known columns. A select on it states the names that the code needs. The checker gives a typed frame with those names: each column keeps the data type of its .cast(...), or takes Unchecked:

load.pymypy: no errors
1import polars as pl
2
3raw = pl.read_csv("trades.csv")
4picked = raw.select("symbol", pl.col("price").cast(pl.Float64))
Resultpickeddeclared
symbolUncheckedpriceFloat64
Revealed type
TypedDataFrame[TypedDict({'symbol': Unchecked, 'price': Float64}, closed=True), None]

The setting elevate_untyped_select controls this, and it is on by default. See Configuration.