Skip to main content

DataScan.from_dict()

Restore a DataScan from a dictionary.

Usage

Source

DataScan.from_dict(d)

The dictionary is the one produced by to_dict(). This reconstructs the profile without needing the original data, so a profile that was stored earlier can be viewed again with get_tabular_report(), queried through summary_data, or used as the baseline in compare().

A restored scan has the statistics but not the data. Its summary_data is a Polars DataFrame, whatever the type of the original table. And when it’s compared with another scan, the statistics are compared as usual, but drift scores (which need the values themselves) are only computed for Boolean columns.

Parameters

d: dict[str, Any]
A dictionary with "metadata" and "columns" keys, as produced by to_dict().

Returns

DataScan
A restored DataScan instance.

Examples

Let’s take a profile of a table of sensor readings as a dictionary, then restore it.

import pointblank as pb
import polars as pl

readings = pl.DataFrame(
    {"sensor": ["T1", "T2", "T3", "T4"], "temp_c": [21.4, 22.1, None, 20.8]}
)

profile = pb.DataScan(readings, tbl_name="readings").to_dict()

restored = pb.DataScan.from_dict(profile)

restored.get_tabular_report()
PolarsreadingsRows4Columns2
Column NA UQ Mean SD Min P5 Q1 Med Q3 P95 Max IQR
string
sensor
String
0
0
4
1
2 0 2 2 2 2 2 2 2 0
numeric
temp_c
Float64
1
0.25
4
1
21.43 0.65 20.8 20.81 21.1 21.4 21.75 22.03 22.1 0.65
String columns statistics regard the string's length.

The report is the same as the one for the original scan, even though restored was made from the dictionary alone. Converting the restored scan back to a dictionary gives the same dictionary:

restored.to_dict() == profile
True

So a profile can go through any number of save-and-restore cycles without losing information.