Skip to main content

MultiValidate.assert_below_threshold()

Raise an AssertionError if any run reached a threshold level.

Usage

Source

MultiValidate.assert_below_threshold(
    level="warning",
    message=None,
)

This is Validate.assert_below_threshold() for all runs at once: if a step of any run reached the threshold level, an AssertionError lists those steps, grouped by run.

Parameters

level: str = "warning"

The threshold level: "warning" (the default), "error", or "critical".

message: str | None = None
A message for the AssertionError. By default, the message lists the steps that reached the level.

Returns

None

Raises

AssertionError

If a step of any run reached the threshold level.

ValueError
If level= isn’t a threshold level.

Examples

The second of these runs reaches the warning level:

import pointblank as pb
import polars as pl

multi = pb.MultiValidate(
    *[
        pb.Validate(data=pl.DataFrame({"a": a}), tbl_name=name, thresholds=(1, 2))
        .col_vals_gt(columns="a", value=0)
        .interrogate()
        for a, name in (([1, 2], "orders"), ([3, -4], "customers"))
    ]
)

multi.assert_below_threshold(level="error")

try:
    multi.assert_below_threshold(level="warning")
except AssertionError as e:
    print(e)
The following steps exceeded the warning threshold level:
Run 2 (customers):
  - Step 1: Expect that values in `a` should be > `0`.

No run reached the error level, so the first assertion passes, and the second fails for the customers run.