Skip to main content

MultiValidate.get_dataframe()

Get the results of every step of every run as a DataFrame.

Usage

Source

MultiValidate.get_dataframe(
    shape="long",
    tbl_type="polars",
    by=None,
)

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. With shape="summary", it gives the table that the summary report shows: a row for each run (or for each table), and with shape="dimensions", the scores of the data quality dimensions of each run. All four 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 last four columns are for the steps that measure a value of the table, like the row count of row_count_match(), the fraction of Null values of col_pct_null(), or the sum of col_sum_eq():

  • measure: the value that the step measured in the run
  • baseline: the value of the step’s baseline(), or the center of the normal range of its anomaly()
  • baseline_lower and baseline_upper: the ends of the normal range of an anomaly()

They’re None for the other steps, and baseline is None for a step that was checked against a fixed value (or that had no baseline yet). With these columns, the measures of a step can be followed over the runs, as in the wide report with values="measure".

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.

The summary table

With shape="summary", there’s a row for each run, in the order of the MultiValidate object, with the values of the summary report of get_tabular_report(). Its columns are:

  • run, tbl_name, label, and time_end: as in the long table
  • status: the status of the run, as "critical", "error", or "warning" (the highest threshold level reached), "failed" (for a run with failing test units that didn’t reach a threshold level), or "passed"
  • steps, steps_passed, and steps_failed: the number of steps, and of those where every test unit passed and where some failed
  • health_score: the health score of the run, from 0 to 100 (see Validate.get_health_score()), or None for a run without any test units

With by="tbl_name", there’s a row for each table instead (in the order the tables first appear), with the values of the table’s latest run. The run column is replaced by runs (the number of runs of the table) and latest_run (the run number of its latest run).

The dimensions table

With shape="dimensions", there’s a row for each data quality dimension of each run (in the order of the runs), with the dimension’s score in the run, as in the scorecard of get_scorecard(). Its columns are:

  • run, tbl_name, label, and time_end: as in the long table
  • dimension: the dimension (e.g., "completeness")
  • n_passed and n: the numbers of passing and of all test units of the run’s steps in the dimension
  • score: the dimension’s score, from 0 to 100 (the share of its test units that passed, as in Validate.get_dimension_scores())

A run has a row for each dimension of its steps that have a result (an inactive step, or one that couldn’t be evaluated, has none). With this table, the scores of the dimensions can be followed over the runs in a chart or a dashboard.

Parameters

shape: Literal["long", "wide", "summary", "dimensions"] = "long"

The shape of the table: "long" (the default) for a row for each step of each run, "wide" for a row for each step and a column for each run, "summary" for a row for each run, or "dimensions" for a row for each data quality dimension of 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()).

by: Literal["tbl_name"] | None = None
For the summary table, None (the default) for a row for each run, or "tbl_name" for a row for each table, with the values of its latest run.

Returns

Any
A table with a row for each step of each run (or, with shape="wide", a row for each step, with shape="summary", a row for each run or table, and with shape="dimensions", a row for each dimension of each run).

Raises

ValueError
If shape=, tbl_type=, or by= 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)
runtbl_namestep_numberunitspass_nfailed_n
i64stri64i64i64i64
1"readings"1330
2"readings"1321

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_keystep_numberfailed_n
strlist[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_namestep_descriptioncolumnssegmentrun_1run_2
strstrstrstrf64f64
null"col_vals_gt""a"null1.00.666667
null"col_vals_not_null""a"nullnull1.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.

The summary table has a row for each run:

(
    pb.MultiValidate(first, second)
    .get_dataframe(shape="summary")
    .select("run", "status", "steps", "steps_failed", "health_score")
)
shape: (2, 5)
runstatusstepssteps_failedhealth_score
i64stri64i64f64
1"passed"10100.0
2"failed"2183.33

The second run has a failing step (with no thresholds set, its status is "failed"), so its health score is lower. Filtering on status is a quick way to find the runs that need a closer look.

The dimensions table has the score of each dimension in each run:

(
    pb.MultiValidate(first, second)
    .get_dataframe(shape="dimensions")
    .select("run", "dimension", "n_passed", "n", "score")
)
shape: (3, 5)
rundimensionn_passednscore
i64stri64i64f64
1"validity"33100.0
2"completeness"33100.0
2"validity"2366.67

The first run has only the validity step, and the second has a completeness step as well (all three values of a are there), while its validity score dropped to about 67%.