Skip to content

Start here

Quickstart

This page takes five minutes. It assumes that you installed Astrolabe and set up the project.

A schema is a class that inherits from Columns. Each field is a column, with a Polars data type. Use the schema in the type TypedDataFrame:

quickstart.pymypy: 1 error
1import polars as pl
2
3from astrolabe import Columns, TypedDataFrame
4
5
6class Trades(Columns):
7 symbol: pl.String
8 price: pl.Float64
9
10
11def cheapest(trades: TypedDataFrame[Trades]) -> TypedDataFrame[Trades]:
12 return trades.sort("prices").head(1)
error: Unknown column "prices" [unknown-column]

Run mypy. The function sorts by prices, and the frame has price, so the checker reports the line.

Correct the name. Then ask mypy for the type of a new frame with reveal_type:

quickstart.pymypy: no errors
1class Trades(Columns):
2 symbol: pl.String
3 price: pl.Float64
4
5
6def cheapest(trades: TypedDataFrame[Trades]) -> TypedDataFrame[Trades]:
7 return trades.sort("price").head(1)
8
9
10trades: TypedDataFrame[Trades]
Resulttrades.with_columns(doubled=pl.col("price") * 2)declaredadded
symbolStringpriceFloat64doubledFloat64
Revealed type
TypedDataFrame[TypedDict({'symbol': String, 'price': Float64, 'doubled': Float64}, closed=True), None]

The new column doubled has the data type Float64, because a Float64 times an integer gives a Float64 in Polars. The checker computes that type with the rules of Polars, so each later step knows the column and its data type.

  • Follow the Tutorial to type a whole pipeline, one idea at a time.
  • Read the Guides for one topic at a time.
  • Look up an error in Error codes.