Introductie van lazy mode

Introductie tot Polars

Liam Brannigan

Data Scientist & Polars Contributor

Eager-modus

(
    pl.read_csv("vacation_rentals.csv")


)
  • Laadt CSV in DataFrame

Lazy-modus

Introductie tot Polars

Eager-modus

(
    pl.read_csv("vacation_rentals.csv")


)
  • Laadt CSV in DataFrame

Lazy-modus

(
    pl.scan_csv("vacation_rentals.csv")


)
  • Start queryplan
  • Leest eerste rijen van CSV
Introductie tot Polars

Eager-modus

(
    pl.read_csv("vacation_rentals.csv")


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

Lazy-modus

(
    pl.scan_csv("vacation_rentals.csv")


)
naive plan: 

Csv SCAN [vacation_rentals.csv]
PROJECT */8 COLUMNS
Introductie tot Polars

Eager-modus

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

)

Lazy-modus

Introductie tot Polars

Eager-modus

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

)

Lazy-modus

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

)
  • Werkt bij queryplan
  • Optimaliseert queryplan
Introductie tot Polars

Geoptimaliseerd queryplan

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

PROJECT 2/8 COLUMNS
  • Optimalisatie: projection pushdown
Introductie tot Polars

Een lazy-query uitvoeren

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

Eager-modus vs. lazy-modus

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

)
  • Regel-voor-regel
(
    pl.scan_csv("vacation_rentals.csv")
    .select("name","price")
    .collect()
)
  • Volledige query
Introductie tot Polars

Eager-modus vs. lazy-modus

Een rennende ijsbeer (Polar Bear) en een slapende Polars-beer

  • stap-voor-stap: eager-modus
  • debuggen: eager-modus
  • performance optimaliseren: lazy-modus
Introductie tot Polars

Laten we oefenen!

Introductie tot Polars

Preparing Video For Download...