Schema.is_valid#

classmethod Schema.is_valid(
df: DataFrame | LazyFrame,
/,
*,
cast: bool = False,
) bool[source]#

Check whether a data frame satisfies the schema.

This method has two major differences to validate():

  • It always collects the input to eagerly evaluate validity and return a boolean value.

  • It does not raise any of the documented exceptions for validate() and instead returns a value of False. Note that it still raises an exception if a lazy frame is provided as input and any logic prior to the validation causes an exception.

Parameters:
  • df – The data frame to check for validity.

  • cast – Whether columns with a wrong data type in the input data frame are cast to the schema’s defined data type before running validation. If set to False, a wrong data type will result in a return value of False.

Returns:

Whether the provided dataframe can be validated with this schema.

Notes

If you want to customize the engine being used for collecting the result within this method, consider wrapping the call in a context manager that sets the engine_affinity in the polars.Config.