Skip to content

Predicates

col() builds the conditions a ColRule or a Check carries. Unlike a raw pl.Expr, a predicate built this way survives a round trip through a spec file -- see Specs as files.

col

col

col(name: str) -> Col

A reference to a column, the starting point of every predicate.

Pred

Pred dataclass

Pred()

Base class of every predicate node. Build one with col().

to_expr

to_expr() -> Expr

This predicate as the Polars expression that evaluates it.

to_data

to_data() -> Any

This predicate as plain data, for writing to a spec file.

to_source

to_source() -> str

This predicate as the col(...) Python that would rebuild it.

children

children() -> tuple[Pred, ...]

The operand nodes this one is built from, in written order.

The three traversals below are derived from this, so a node only has to say what it is made of. A leaf returns nothing.

rebuild

rebuild(children: tuple[Pred, ...]) -> Pred

This node with children in place of its own, same order.

A leaf ignores them and returns itself.

root_names

root_names() -> set[str]

Every column name this predicate reads.

literals

literals() -> list[Any]

Every constant this predicate compares against.

Used to check a rule's operands against the column's own domain.

rename

rename(mapping: Mapping[str, str]) -> Pred

The same predicate with its columns renamed by mapping.

Derived, so a node cannot be added that silently fails to rename -- which would leave a rule pointing at a column that no longer exists and only surface much later, as a spec failing its own validation.

equals

equals(other: object) -> bool

Structural equality, since == builds a predicate.

is_in

is_in(values: Sequence[Any]) -> IsIn

A predicate true where this value is one of values.

is_null

is_null() -> IsNull

A predicate true where this value is null.

is_not_null

is_not_null() -> Not

A predicate true where this value is present.

is_between

is_between(lower: Any, upper: Any) -> Between

A predicate true where this value falls within [lower, upper].