CommencerCommencez gratuitement

Ignoring parse errors

A bad value, the literal text "unknown", has slipped into the checkouts column of the vendor export. Polars normally fails when it can't parse a value into the inferred dtype. Tell Polars to skip these errors so the team can still load the rest of the data.

A normal row and the row with the bad value are printed for you so you can see what's going on.

Cet exercice fait partie du cours

<cours>Scaling and Optimizing Data Pipelines with Polars</cours>
Voir le cours

Instructions de l’exercice

  • Add the argument that tells Polars to set bad values to null and continue scanning.

Exercice interactif pratique

Essayez cet exercice en complétant ce code d’exemple.

result = pl.scan_csv(
    MESSY_CSV_PATH,
    separator=";",
    skip_rows=2,
    schema_overrides={
        "checkouts": pl.Int64,
        "branch_code": pl.String,
    },
    # Tolerate values that don't fit the schema
    ____=____,
).collect()
print(result)
Modifier et exécuter le code