pysparky_data_quality
Type part of a name or a dotted path
Composable data-quality rules for native PySpark DataFrames.
Classes
| Name | Description |
|---|---|
CheckResult | Serializable status and metrics for one named validation check. |
DataValidator | Immutable, ordered collection of uniquely named validation rules. |
ValidationReport | Immutable versioned collection of row, dataset, and schema results. |
ValidationRule | A named boolean Column expression with an explicit SQL NULL policy. |
Modules
expectationsExplicit dataset and top-level schema expectations for PySpark.reportVersioned, serializable results from explicit validation checks.rulesFactories for reusable, lazy PySpark row-rule expressions.validationImmutable definitions and ordered collections of row validation rules.
CheckResultclassdataclass#
pysparky_data_quality.reportView sourceclass CheckResult(check_id: str, scope: Scope, status: CheckStatus, metrics: tuple[tuple[str, MetricValue], ...] = (), null_policy: str | None = None, violations: tuple[str, ...] = (), error_type: str | None = None, error_message: str | None = None)Serializable status and metrics for one named validation check.
check_idattributeinstance attribute#
check_id: strerror_messageattributeclass attributeinstance attribute#
error_message: str | None = Noneerror_typeattributeclass attributeinstance attribute#
error_type: str | None = Nonemetricsattributeclass attributeinstance attribute#
metrics: tuple[tuple[str, MetricValue], ...] = ()null_policyattributeclass attributeinstance attribute#
null_policy: str | None = Nonescopeattributeinstance attribute#
scope: Scopestatusattributeinstance attribute#
status: CheckStatusviolationsattributeclass attributeinstance attribute#
violations: tuple[str, ...] = ()from_errormethodclassmethod#
def from_error(check_id: str, scope: Scope, error: Exception) -> CheckResultCreate an execution-error result without collecting input rows.
from_outcomemethodclassmethod#
def from_outcome(check_id: str, scope: Scope, outcome: ExpectationOutcome) -> CheckResultConvert an already evaluated dataset/schema outcome without I/O.
to_dictmethod#
def to_dict() -> dict[str, object]Return this result as JSON-serializable built-in values.
DataValidatorclassdataclass#
pysparky_data_quality.validationView sourceclass DataValidator(rules: Iterable[ValidationRule] = ())Immutable, ordered collection of uniquely named validation rules.
The registry stores expressions only. It does not accept a DataFrame, create a SparkSession, or trigger Spark work.
rulesproperty#
rules: tuple[ValidationRule, ...]Rules in their declared evaluation and reporting order.
annotatemethod#
def annotate(dataframe: DataFrame) -> DataFrameAdd one boolean result column per rule without running an action.
Each result column uses its rule’s name. Existing columns are preserved in order. Names that collide under case-insensitive comparison are rejected so behavior does not depend on Spark’s resolver setting.
splitmethod#
def split(dataframe: DataFrame) -> tuple[DataFrame, DataFrame]Return lazy (valid, invalid) frames with the original schema.
A row is valid only when every normalized rule predicate is true. With no rules, the empty conjunction is true and all rows are valid. The two outputs are mutually exclusive and collectively exhaustive.
validatemethod#
def validate(dataframe: DataFrame) -> ValidationReportEvaluate row rules in one explicit action and return a report.
Each rule result includes total and failed row counts. Empty validators
return an empty report without scanning the DataFrame. Spark failures
become error results; invalid Python definitions still raise.
with_rulemethod#
def with_rule(rule: ValidationRule) -> DataValidatorReturn a new validator with rule appended, preserving this instance.
ValidationReportclassdataclass#
pysparky_data_quality.reportView sourceclass ValidationReport(checks: tuple[CheckResult, ...] = (), schema_version: int = 1)Immutable versioned collection of row, dataset, and schema results.
Version 1 uses JSON scalar metrics, ordered checks, and no raw row samples.
checksattributeclass attributeinstance attribute#
checks: tuple[CheckResult, ...] = ()schema_versionattributeclass attributeinstance attribute#
schema_version: int = 1passedproperty#
passed: boolWhether the report contains no failed or errored checks.
statusproperty#
status: ReportStatusReturn aggregate status, preserving execution errors distinctly.
combinemethodclassmethod#
def combine(*reports: ValidationReport) -> ValidationReportCombine reports in argument order, rejecting duplicate check IDs.
from_errorsmethodclassmethod#
def from_errors(errors: Mapping[str, tuple[Scope, Exception]]) -> ValidationReportCompose captured execution errors without retrying the checks.
from_outcomesmethodclassmethod#
def from_outcomes(outcomes: Mapping[str, tuple[Scope, ExpectationOutcome]]) -> ValidationReportCompose named, already evaluated expectation outcomes without I/O.
to_dictmethod#
def to_dict() -> dict[str, object]Return a stable versioned structure suitable for JSON encoding.
ValidationRuleclassdataclass#
pysparky_data_quality.validationView sourceclass ValidationRule(name: str, condition: Column, null_policy: NullPolicy = 'fail')A named boolean Column expression with an explicit SQL NULL policy.
condition must be a boolean PySpark Column. Its raw SQL result may be
true, false, or NULL. Calling predicate maps a NULL result to false by
default, or to true when null_policy is "pass". This constructs a
lazy Column expression and performs no Spark action.
conditionattributeinstance attribute#
condition: Columnnameattributeinstance attribute#
name: strnull_policyattributeclass attributeinstance attribute#
null_policy: NullPolicy = 'fail'predicatemethod#
def predicate() -> ColumnReturn a boolean Column with the configured NULL policy applied.