測試綱要(schema)
團隊已修正 expected DataFrame 中的值,但 Polars 推斷的 total_checkouts 是 64 位元,而管線產生的是 32 位元。系統已為你列出兩個綱要,方便你查看不一致之處。請修正預期的資料型別,然後斷言兩者綱要一致。
actual、expected,以及 assert_schema_equal 已預先載入。
本練習屬於課程
使用 Polars 擴充與最佳化資料管線
練習說明
- 將
expected中的total_checkouts轉型為pl.Int32。 - 斷言
actual與expected的綱要相同。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Match the dtype the pipeline produces
expected = expected.with_columns(
pl.col("total_checkouts").cast(pl.____)
)
# Schema-level assertion
____(actual.schema, expected.schema)
print("Schema assertion passed.")
print(actual.schema)