Skip to content

Data quality

Functions

NameDescription
expect_any_to_oneA decorator function that ensures an N:1 relationship between col1 and col2,
expect_criteriaA decorator function that ensures a specific criterion on a Spark DataFrame.
expect_one_to_oneA decorator function that ensures a 1:1 relationship between col1 and col2,
expect_typeA decorator function that verifies the data type of a specified column in a Spark DataFrame.
expect_uniqueA decorator function that ensures the uniqueness of a column in a Spark DataFrame.

expect_any_to_onefunction#

def expect_any_to_one(col1: str | Sequence[str], col2: str | Sequence[str])

A decorator function that ensures an N:1 relationship between col1 and col2, meaning each value in col1 corresponds to only one distinct value in col2.

Parameters

NameTypeDescription
col1str | Sequence[str]Name of the column or a tuple of column names.
col2str | Sequence[str]Name of the column or a tuple of column names.

expect_criteriafunction#

def expect_criteria(criteria)

A decorator function that ensures a specific criterion on a Spark DataFrame.

Parameters

NameTypeDescription
criteriapyspark.sql.column.ColumnThe filter criterion to be applied to the DataFrame.

Returns

function
A decorated function that checks the criterion.

Raises

AssertionError
If the filtered count and unfiltered count of the DataFrame are not equal.

expect_one_to_onefunction#

def expect_one_to_one(col1: str | Sequence[str], col2: str | Sequence[str])

A decorator function that ensures a 1:1 relationship between col1 and col2, meaning each value in col1 corresponds to only one distinct value in col2 and vice-versa.

Parameters

NameTypeDescription
col1str | Sequence[str]Name of the column or a tuple of column names.
col2str | Sequence[str]Name of the column or a tuple of column names.

expect_typefunction#

def expect_type(col_name, col_type)

A decorator function that verifies the data type of a specified column in a Spark DataFrame.

Parameters

NameTypeDescription
col_namestrThe column’s name.
col_typepyspark.sql.types.DataTypeThe expected data type for the column.

Returns

function
A decorated function that checks the column’s data type.

Raises

AssertionError
If the column’s data type does not match the expected type.

expect_uniquefunction#

def expect_unique(col_name)

A decorator function that ensures the uniqueness of a column in a Spark DataFrame.

Parameters

NameTypeDescription
col_namestrThe column’s name.

Returns

function
A decorated function that checks the column’s uniqueness.

Raises

AssertionError
If the column’s count and distinct count are not equal.