Assert a frame still obeys a canonical schema, then return it (for chaining).
Use after slicing/grouping/mutating a canonical frame (e.g. before appending to the
Parquet lake) to fail fast with a clear SchemaError instead of corrupting the
dataset. schema is one of SCHEMAS ("station_status", "vehicle_status"…).
See Also
coerce_schema : Coerce to the schema instead.
SchemaError : Raised on validation failure.
Source code in src/gbfs_toolkit/core/models.py
| def validate_schema(df: pd.DataFrame, schema: str) -> pd.DataFrame:
"""Assert a frame still obeys a canonical schema, then return it (for chaining).
Use after slicing/grouping/mutating a canonical frame (e.g. before appending to the
Parquet lake) to fail fast with a clear [`SchemaError`][gbfs_toolkit.SchemaError] instead of corrupting the
dataset. ``schema`` is one of [`SCHEMAS`][gbfs_toolkit.SCHEMAS] (``"station_status"``, ``"vehicle_status"``…).
See Also
--------
[`coerce_schema`][gbfs_toolkit.coerce_schema] : Coerce to the schema instead.
[`SchemaError`][gbfs_toolkit.SchemaError] : Raised on validation failure.
"""
require_columns(df, _schema_columns(schema), what=f"validate_schema({schema!r})")
return df
|