Collection.filter#

classmethod Collection.filter(
data: Mapping[str, FrameType],
/,
*,
cast: bool = False,
eager: bool = True,
) CollectionFilterResult[Self][source]#

Filter the members data frame by their schemas and the collection’s filters.

Parameters:
  • data – The members of the collection which ought to be filtered. The dictionary must contain exactly one entry per member with the name of the member as key, except for optional members which may be missing. All data frames passed here will be eagerly collected within the method, regardless of whether they are a DataFrame or LazyFrame.

  • cast – Whether columns with a wrong data type in the member data frame are cast to their schemas’ defined data types if possible.

  • eager – Whether the filter operation should be performed eagerly. Note that until pola-rs/polars#24129 is released, eagerly filtering can provide significant speedups.

Returns:

A named tuple with fields result and failure. The result field provides a collection with all members filtered for the rows passing validation. Just like for validation, all members are guaranteed to maintain their input order. The failure field provides a dictionary mapping member names to their respective failure information.

Raises:

ValueError – If an insufficient set of input data frames is provided, i.e. if any required member of this collection is missing in the input.