When it comes to high-performance computing, one of the strengths of Polars is that it supports lazy evaluation. Lazy evaluation instantly returns a future that can be used down the code without waiting for the result of the computation to get calculated. It also allows the query optimizer to combine operations, very much the way compiled languages work.
If you want to speedup your code, use lazy execution whenever possible.
Try to use the lazy API from the start, when reading a file.
In previous examples, we used read_csv to read our data. This returns a Polars DataFrame. Instead, you can use scan_csv to create a LazyFrame:
import polars as plurl ="https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"df = pl.read_csv(url)df_lazy = pl.scan_csv(url)print(type(df))print(type(df_lazy))