แนะนำ lazy mode

Introduction to Polars

Liam Brannigan

Data Scientist & Polars Contributor

Eager mode

(
    pl.read_csv("vacation_rentals.csv")


)
  • โหลด CSV เข้า DataFrame

Lazy mode

Introduction to Polars

Eager mode

(
    pl.read_csv("vacation_rentals.csv")


)
  • โหลด CSV เข้า DataFrame

Lazy mode

(
    pl.scan_csv("vacation_rentals.csv")


)
  • เริ่มต้น query plan
  • อ่านแถวแรกของ CSV
Introduction to Polars

Eager mode

(
    pl.read_csv("vacation_rentals.csv")


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

Lazy mode

(
    pl.scan_csv("vacation_rentals.csv")


)
naive plan: 

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

Eager mode

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

)

Lazy mode

Introduction to Polars

Eager mode

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

)

Lazy mode

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

)
  • อัปเดต query plan
  • ปรับแต่ง query plan
Introduction to Polars

Query plan ที่ผ่านการปรับแต่ง

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

PROJECT 2/8 COLUMNS
  • การปรับแต่ง: projection pushdown
Introduction to Polars

การรัน lazy query

(
    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 mode vs. lazy mode

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

)
  • ทีละบรรทัด
(
    pl.scan_csv("vacation_rentals.csv")
    .select("name","price")
    .collect()
)
  • ทั้ง query
Introduction to Polars

Eager mode vs. lazy mode

หมีโพลาร์กำลังวิ่งและหมี Polars กำลังนอนหลับ

  • ทีละขั้นตอน: eager mode
  • การดีบัก: eager mode
  • ประสิทธิภาพที่ปรับแต่งแล้ว: lazy mode
Introduction to Polars

มาฝึกกันเถอะ!

Introduction to Polars

Preparing Video For Download...