Schema.create_empty_if_none#

classmethod Schema.create_empty_if_none(
df: DataFrame[Self] | LazyFrame[Self] | None,
*,
lazy: bool = False,
) DataFrame[Self] | LazyFrame[Self][source]#

Impute None input with an empty, schema-compliant lazy or eager data frame or return the input as lazy or eager frame.

Parameters:
  • df – The data frame to check for None. If it is not None, it is returned as lazy or eager frame. Otherwise, a schema-compliant data or lazy frame with no rows is returned.

  • lazy – Whether to return a lazy data frame. If True, returns a lazy frame with this Schema. Otherwise, returns an eager frame.

Returns:

The given data frame df as lazy or eager frame, if it is not None. An instance of polars.DataFrame or polars.LazyFrame with this schema’s defined columns and their data types, but no rows, otherwise.