import pointblank as pb
import polars as pl
def orders_on(n_rows):
return pl.DataFrame({"amount": [20.0] * n_rows})
runs = [
pb.Validate(data=orders_on(n), tbl_name="orders").row_count_match(count=100).interrogate()
for n in [98, 104, 101]
]
history = pb.MultiValidate(*runs)baseline()
Use a value from earlier runs of the validation as the expected value of a step.
Usage
baseline(
stat="last",
window=None,
min_runs=1,
)A step that measures something about the table (its row count, its column count, the fraction of Null values in a column, or the sum, average, or standard deviation of a column) usually compares the measure with a fixed value. With baseline() in place of that value, the step compares the measure with what it was in earlier runs instead: “the row count is within 10% of the last run’s”, or “the sum of amount is within 20% of the median of the last 7 runs”.
The earlier runs are given to the validation with Validate(history=), as a directory (or a glob pattern, or a list of paths) of results files written by write_results(), or as a MultiValidate object. At interrogation, the baseline is resolved to a number from the runs of the same table (the same tbl_name=) that ended before this run started, and the step then runs as if that number had been given: tol= and the comparison apply as they always do. So col_sum_ge(columns="amount", value=pb.baseline(), tol=0.05) checks that the sum didn’t fall more than 5% below that of the last run.
baseline() can be used in these places:
count=ofrow_count_match()andcol_count_match()p=ofcol_pct_null()value=of the aggregate methods, likecol_sum_eq(),col_avg_gt(), andcol_sd_le()
Parameters
stat: Literal["last", "mean", "median", "min", "max"] = "last"-
How the earlier values of the measure are summarized:
"last"(the default) takes the value of the latest run, and"mean","median","min", and"max"take the mean, median, lowest, or highest value of the runs in the window. window: int | None = None-
The number of earlier runs to use: the last
window=runs that have the measure. The default,None, uses all of them. This has no effect withstat="last". min_runs: int = 1-
The number of earlier runs needed for a baseline. With fewer runs than this (as on the first run of a new validation), there’s no baseline to compare with, so the step passes and the report has a note saying so. The default is
1.
Returns
Baseline- A marker for the expected value, which is resolved when the validation is interrogated.
Finding The Earlier Values
The values of a measure are found in the earlier runs by a key made from what is measured: the measure (e.g., the row count, or the sum), the column, and the step’s pre= and segment. The value being compared with, the tolerance, and the comparison aren’t part of the key, so the history of a measure isn’t lost when the check around it changes. A row_count_match() step with count=1000 in earlier runs and count=pb.baseline() now shares the history of the row count, and col_sum_eq() and col_sum_ge() steps on the same column share the history of the sum.
Runs that don’t have the measure aren’t counted: those without a step for it, those whose step couldn’t be evaluated, and those written by versions of Pointblank before measures were kept in results files. A step that uses a baseline raises an error at interrogation if the validation has no tbl_name= or no history=, since the earlier runs couldn’t be found without them.
Examples
Let’s say that an orders table is validated every day. Here are three days of runs, each checking the table’s row count against a fixed value:
Today’s table has 82 rows. Rather than a fixed count, the step can compare the row count with that of the last run, allowing 10% either way:
validation = (
pb.Validate(data=orders_on(82), tbl_name="orders", history=history)
.row_count_match(count=pb.baseline(), tol=0.1)
.interrogate()
)
validation| STEP | COLUMNS | VALUES | TBL | EVAL | UNITS | PASS | FAIL | W | E | C | EXT | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| #4CA64C66 | 1 |
row_count_match()
|
✓ | 1 | 0 0.00 |
1 1.00 |
— | — | — | — | |||
Notes Step 1 (baseline) Baseline: the value of the last run (2026-12-04 20:53 UTC). | |||||||||||||
The last run had 101 rows, which is the expected value shown in the report, and 82 rows is more than 10% fewer, so the step fails. The note below the table says where the baseline came from.
A baseline can also summarize several runs. Here, the sum of amount is compared with the median of the last three runs, which is steadier than the value of any one of them:
validation = (
pb.Validate(data=orders_on(82), tbl_name="orders", history=history)
.col_sum_eq(columns="amount", value=pb.baseline(stat="median", window=3), tol=0.2)
.interrogate()
)
validation| STEP | COLUMNS | VALUES | TBL | EVAL | UNITS | PASS | FAIL | W | E | C | EXT | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| #4CA64C | 1 |
col_sum_eq()
|
✓ | 1 | 1 1.00 |
0 0.00 |
— | — | — | — | |||
Notes Step 1 (baseline) No baseline yet: too few earlier runs to compare with (found: 0, needed: 1), so this step passed. | |||||||||||||
None of the earlier runs had a step for the sum of amount, so there’s no baseline yet. The step passes, with a note saying so, and the sum it measured becomes part of the history once this run’s results are kept (with write_results(), in a directory that’s given to history= next time).
See Also
- Validate
-
The
history=argument, which gives the earlier runs. - write_results()
-
Keep the results of a run for later runs to compare with.
- ref()
-
Compare with a column of reference data instead.