Each variable that declares missing values (such as the user-defined missing values of an SPSS variable, or the missing-value markers of a Frictionless schema) gets a spec made by its to_missing_spec() method. The dictionary can be given to missing_vals_tbl() as its missing=, and a single spec from it can be given to the missing= parameter of a validation method such as col_vals_regex().
The specs keep the values as they were declared. Frictionless and CSVW markers are strings (like "NA") and are declared for every field, but in a table read with typed columns they can only appear in the string columns. Keep only the specs of those columns before using them, since a string marker can’t be compared with a numeric or date column.
Returns
dict[str, MissingSpec]
A dictionary from column name to MissingSpec. Variables that don’t declare missing values aren’t included.
Examples
The bundled Frictionless Data Package declares "NA" and "N/A" as missing-value markers, so every one of its variables gets a spec:
import pointblank as pbmeta = pb.import_metadata(pb.load_metadata_example("datapackage.json"))specs = meta.missing_specs()print(list(specs))print(specs["customer_id"].reasons)
The reasons were made from the markers, as no labels were declared for them. Let’s keep the specs of the string columns and use one of them in a validation step:
import polars as plstring_specs = { name: spec for name, spec in specs.items() if meta.get_variable(name).dtype =="String"}tbl = pl.DataFrame({"customer_id": ["CUST-101", "N/A", "CUST-103", "NA"]})( pb.Validate(data=tbl) .col_vals_regex(columns="customer_id", pattern="^CUST-[0-9]+$") .col_vals_regex( columns="customer_id", pattern="^CUST-[0-9]+$", missing=string_specs["customer_id"] ) .interrogate())
Without the spec, the "N/A" and "NA" markers fail the pattern check in step 1. With it, step 2 treats them as missing data instead, so all four rows pass. The string_specs dictionary could be given to missing_vals_tbl() in the same way, to summarize the missing data in each string column of a table.