from functools import reduce
from typing import cast


def cast_schema(df, schema):
    """Enforce the schema on the data frame.

    Args:
        df (DataFrame): The dataframe.
        schema (list): The simple schema to be applied.

    Returns:
        A data frame converted to the schema.
    """
    spark_schema = schema.to_spark()
    # return spark_session.createDataFrame(df.rdd, schema=spark_schema)
    return reduce(cast,
                  spark_schema.fields,
                  df.select(*spark_schema.fieldNames()))