Check whether one or more columns exist in a table.
USAGE
has_columns(*columns)
This function returns a callable that, when given a table, checks whether all specified columns are present. It is primarily designed for use with the active= parameter of validation methods. When a validation step has active=has_columns("col_a", "col_b"), the step will be skipped (made inactive) if either col_a or col_b is missing from the target table.
The callable is evaluated against the original table before any pre= processing is applied. This means the column check is performed on the raw input data, not on a pre-processed version of it.
A note is attached to any skipped step in the validation report explaining which columns were not found.
Parameters
*columns:str | list[str]=()
One or more column names to check for in the table. Each argument can be a string or a list of strings. All specified columns must be present for the callable to return True.
Returns
Callable[[Any], bool]
A callable that accepts a table and returns True if every column in columns exists in the table, False otherwise.
Raises
:ValueError
If no column names are provided.
:TypeError
If any of the provided column names is not a string or list of strings.
Examples
Using has_columns() with the active= parameter to conditionally run a validation step:
The first step ran because column a exists. The second step was skipped because column z is missing, and the report note explains which column was not found.
When checking for multiple columns, the step is only active when all columns are present: