LoslegenKostenlos starten

Testing schemas

The team fixed the values in their expected DataFrame, but Polars inferred total_checkouts as 64-bit while the pipeline produces 32-bit. The two schemas are printed for you so you can see the mismatch. Fix the expected dtype, then assert the schemas match.

actual, expected, and assert_schema_equal are preloaded.

Diese Übung ist Teil des Kurses

<Kurs>Scaling and Optimizing Data Pipelines with Polars</Kurs>
Kurs ansehen

Übungsanweisungen

  • Cast total_checkouts in expected to pl.Int32.
  • Assert that the schemas of actual and expected are equal.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen