pysparky_data_quality.expectations
Explicit dataset and top-level schema expectations for PySpark.
Attributes
| Name | Description |
|---|---|
Cardinality | No description. |
NullPolicy | No description. |
Classes
| Name | Description |
|---|---|
ExpectationDefinitionError | An expectation or its DataFrame inputs are invalid or ambiguous. |
ExpectationEvaluationError | PySpark failed while evaluating a dataset or schema expectation. |
ExpectationOutcome | Immutable result from one explicit expectation evaluation. |
Functions
| Name | Description |
|---|---|
cardinality | Check key-to-key cardinality within one DataFrame. |
row_count | Check inclusive row-count bounds with one aggregate action. |
schema_matches | Compare top-level schema metadata without scanning DataFrame rows. |
unique | Check uniqueness of one or more key columns with one aggregate action. |
Cardinalityattributemodule attribute#
Cardinality = Literal['many_to_one', 'one_to_many', 'one_to_one']NullPolicyattributemodule attribute#
NullPolicy = Literal['fail', 'equal', 'distinct']ExpectationDefinitionErrorclass#
class ExpectationDefinitionError(ValueError)Bases: ValueError
An expectation or its DataFrame inputs are invalid or ambiguous.
ExpectationEvaluationErrorclass#
class ExpectationEvaluationError(RuntimeError)Bases: RuntimeError
PySpark failed while evaluating a dataset or schema expectation.
ExpectationOutcomeclassdataclass#
class ExpectationOutcome(passed: bool, metrics: tuple[tuple[str, MetricValue], ...] = (), violations: tuple[str, ...] = ())Immutable result from one explicit expectation evaluation.
Metrics are stored as an ordered tuple of key/value pairs so the outcome remains immutable and straightforward to serialize in a later report.
cardinalityfunction#
def cardinality(dataframe: DataFrame, source: str | Iterable[str], target: str | Iterable[str], *, relationship: Cardinality = 'many_to_one', null_policy: NullPolicy = 'equal') -> ExpectationOutcomeCheck key-to-key cardinality within one DataFrame.
many_to_one requires each source key to map to at most one target key;
one_to_many reverses that constraint; one_to_one requires both.
Exact duplicate source/target pairs do not violate a relationship. Calling
this function is an explicit Spark action boundary.
row_countfunction#
def row_count(dataframe: DataFrame, *, min_rows: int | None = None, max_rows: int | None = None) -> ExpectationOutcomeCheck inclusive row-count bounds with one aggregate action.
schema_matchesfunction#
def schema_matches(dataframe: DataFrame, *, required_columns: str | Iterable[str] = (), forbidden_columns: str | Iterable[str] = (), data_types: Mapping[str, str | DataType] | None = None, nullable: Mapping[str, bool] | None = None) -> ExpectationOutcomeCompare top-level schema metadata without scanning DataFrame rows.
String types are compared to the canonical result of PySpark’s
DataType.typeName(). Nested type matching is not supported; expected
type strings for arrays, maps, structs, and parameterized nested types are
rejected.
uniquefunction#
def unique(dataframe: DataFrame, columns: str | Iterable[str], *, null_policy: NullPolicy = 'equal') -> ExpectationOutcomeCheck uniqueness of one or more key columns with one aggregate action.
fail rejects any row with a NULL key and also checks duplicate groups;
equal treats NULL values as equal when identifying duplicate groups;
distinct excludes rows with any NULL key from duplicate detection.
Calling this function is an explicit Spark action boundary.