Představení líného režimu

Introduction to Polars

Liam Brannigan

Data Scientist & Polars Contributor

Eager režim

(
    pl.read_csv("vacation_rentals.csv")


)
  • Načte CSV do DataFrame

Lazy režim

Introduction to Polars

Eager režim

(
    pl.read_csv("vacation_rentals.csv")


)
  • Načte CSV do DataFrame

Lazy režim

(
    pl.scan_csv("vacation_rentals.csv")


)
  • Zahájí plán dotazu
  • Přečte první řádky CSV
Introduction to Polars

Eager režim

(
    pl.read_csv("vacation_rentals.csv")


)
| name     | type    | ... | beach |
| ---      | ---     | ... | ---   |
| str      | str     | ... | bool  |
|----------|---------| ... |-------|
| Waves    | Cottage | ... | false |
| Seashell | Cottage | ... | true  |
| ...      | ...     | ... | ...   |

Lazy režim

(
    pl.scan_csv("vacation_rentals.csv")


)
naive plan: 

Csv SCAN [vacation_rentals.csv]
PROJECT */8 COLUMNS
Introduction to Polars

Eager režim

(
    pl.read_csv("vacation_rentals.csv")
    .select("name","price")

)

Lazy režim

Introduction to Polars

Eager režim

(
    pl.read_csv("vacation_rentals.csv")
    .select("name","price")

)

Lazy režim

(
    pl.scan_csv("vacation_rentals.csv")
    .select("name","price")

)
  • Aktualizuje plán dotazu
  • Optimalizuje plán dotazu
Introduction to Polars

Optimalizovaný plán dotazu

print(
    pl.scan_csv("vacation_rentals.csv")
    .select("name","price")
    .explain()
)
Csv SCAN [vacation_rentals.csv]

PROJECT 2/8 COLUMNS
  • Optimalizace: projection pushdown
Introduction to Polars

Spuštění lazy dotazu

(
    pl.scan_csv("vacation_rentals.csv")
    .select("name","price")
    .collect()
)
shape: (49, 2)
| name      | price |
| ---       | ---   |
| str       | i64   |
|-----------|-------|
| Waves     | 540   |
| Seashells | 540   |
| ...       | ...   |
Introduction to Polars

Eager vs. lazy režim

(
    pl.read_csv("vacation_rentals.csv")
    .select("name","price")

)
  • Řádek po řádku
(
    pl.scan_csv("vacation_rentals.csv")
    .select("name","price")
    .collect()
)
  • Celý dotaz
Introduction to Polars

Eager vs. lazy režim

Běžící polární medvěd a spící medvěd Polars

  • krok za krokem: eager režim
  • ladění chyb: eager režim
  • optimalizovaný výkon: lazy režim
Introduction to Polars

Pojďme si procvičit!

Introduction to Polars

Preparing Video For Download...