Get the results of every step of every run as a DataFrame.
MultiValidate.get_dataframe(
shape="long",
tbl_type="polars",
)
By default, the get_dataframe() method stacks the results of the runs (from Validate.get_dataframe_report()) in one table, with a row for each step of each run. With shape="wide", it gives the table that the wide report shows instead: a row for each step, and a column for each run. Both are described below.
The long table
The first columns say which run the row is from:
run: the run number (1 is the first run, in the order of the MultiValidate object)
tbl_name: the name of the run’s table (tbl_name= of Validate)
label: the label of the run’s validation
time_end: when the run’s interrogation ended (in UTC)
step_key: a key that identifies the step across runs
The other columns are those of get_dataframe_report(), from active and step_number to segmented. This table is the place to start for a dashboard, a log of results, or an analysis of how the results change between runs.
The step key is the same for steps that check the same thing in different runs, even if they have different step numbers (because steps were added or removed between the runs), so it’s what to group by to follow a step over the runs. It’s a hash of the step’s method, columns, values, na_pass=, pre= function (by its source code), and segment. Other arguments, like the thresholds and the brief, don’t change it, so they can be edited without breaking the history of the step. A step with a column selector or segments= is checked as a step for each column and segment, and each of those has its own key.
The wide table
With shape="wide", the steps of the runs are matched by their step keys (within each table), as in the wide report of get_tabular_report(), so there’s a row for each step, in the order the steps first appear. Its columns are:
tbl_name: the name of the table of the runs that have the step
step_key: the step’s key (a step without a key has a row of its own)
step_description: the step’s validation method (e.g., "col_vals_gt")
columns: the column the step checks (the names separated by commas, for a step on several columns)
segment: the step’s segment, as column / value (None for a step that isn’t segmented)
run_1, run_2, …: the fraction of test units that passed in each run
A run’s value is None if the run doesn’t have the step, or if the step has no result in it (because it was inactive or couldn’t be evaluated). The text columns are from the latest run that has the step.
Parameters
shape: Literal["long", "wide"] = "long"
-
The shape of the table: "long" (the default) for a row for each step of each run, or "wide" for a row for each step and a column for each run.
tbl_type: Literal["polars", "pandas", "duckdb"] = "polars"
-
The type of table to return:
"polars" (the default), "pandas", or "duckdb" (an Ibis table, as in get_dataframe_report()).
Returns
Any
-
A table with a row for each step of each run (or, with
shape="wide", a row for each step).
Raises
ValueError
-
If
shape= or tbl_type= isn’t one of the allowed values, or if there are no runs.
Examples
Here are two runs of a validation with one step:
import pointblank as pb
import polars as pl
runs = [
pb.Validate(data=pl.DataFrame({"a": a}), tbl_name="readings")
.col_vals_gt(columns="a", value=0)
.interrogate()
for a in ([1, 2, 3], [4, -5, 6])
]
results = pb.MultiValidate(*runs).get_dataframe()
results.select("run", "tbl_name", "step_number", "units", "pass_n", "failed_n")
shape: (2, 6)| run | tbl_name | step_number | units | pass_n | failed_n |
|---|
| i64 | str | i64 | i64 | i64 | i64 |
| 1 | "readings" | 1 | 3 | 3 | 0 |
| 2 | "readings" | 1 | 3 | 2 | 1 |
Since it’s a regular DataFrame, it can be filtered and summarized like any other. For example, results.filter(~pl.col("all_units_passed")) gives just the steps that had failing test units, with the run each one is in.
Now suppose that a step was added at the start of the validation before the second run, so the col_vals_gt() step is step 1 in the first run and step 2 in the second:
first = (
pb.Validate(data=pl.DataFrame({"a": [1, 2, 3]}))
.col_vals_gt(columns="a", value=0)
.interrogate()
)
second = (
pb.Validate(data=pl.DataFrame({"a": [4, -5, 6]}))
.col_vals_not_null(columns="a")
.col_vals_gt(columns="a", value=0)
.interrogate()
)
results = pb.MultiValidate(first, second).get_dataframe()
(
results.group_by("step_key", maintain_order=True)
.agg(pl.col("step_number"), pl.col("failed_n"))
)
shape: (2, 3)| step_key | step_number | failed_n |
|---|
| str | list[i64] | list[i64] |
| "36bcfc01f83f389f9c398cf9d474e3… | [1, 2] | [0, 1] |
| "f3bf025f5995b4b1dff2974d23aaa0… | [1] | [0] |
Grouping by step_key puts the col_vals_gt() steps of both runs together (with step numbers 1 and 2), and the new col_vals_not_null() step, which only the second run has, in a group of its own.
The wide table does that matching already, with a row for each step and a column for each run:
pb.MultiValidate(first, second).get_dataframe(shape="wide").drop("step_key")
shape: (2, 6)| tbl_name | step_description | columns | segment | run_1 | run_2 |
|---|
| str | str | str | str | f64 | f64 |
| null | "col_vals_gt" | "a" | null | 1.0 | 0.666667 |
| null | "col_vals_not_null" | "a" | null | null | 1.0 |
The col_vals_gt() step’s fraction passed went from 1.0 in the first run to about 0.67 in the second. The col_vals_not_null() step has null for the first run, since that run doesn’t have it.