Skip to content

pysparky_data_quality

Type part of a name or a dotted path

Composable data-quality rules for native PySpark DataFrames.

Classes

NameDescription
CheckResultSerializable status and metrics for one named validation check.
DataValidatorImmutable, ordered collection of uniquely named validation rules.
ValidationReportImmutable versioned collection of row, dataset, and schema results.
ValidationRuleA 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#

class 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: str

error_messageattributeclass attributeinstance attribute#

error_message: str | None = None

error_typeattributeclass attributeinstance attribute#

error_type: str | None = None

metricsattributeclass attributeinstance attribute#

metrics: tuple[tuple[str, MetricValue], ...] = ()

null_policyattributeclass attributeinstance attribute#

null_policy: str | None = None

scopeattributeinstance attribute#

scope: Scope

statusattributeinstance attribute#

status: CheckStatus

violationsattributeclass attributeinstance attribute#

violations: tuple[str, ...] = ()

from_errormethodclassmethod#

def from_error(check_id: str, scope: Scope, error: Exception) -> CheckResult

Create an execution-error result without collecting input rows.

from_outcomemethodclassmethod#

def from_outcome(check_id: str, scope: Scope, outcome: ExpectationOutcome) -> CheckResult

Convert 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#

class 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) -> DataFrame

Add 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) -> ValidationReport

Evaluate 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) -> DataValidator

Return a new validator with rule appended, preserving this instance.

ValidationReportclassdataclass#

class 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 = 1

passedproperty#

passed: bool

Whether the report contains no failed or errored checks.

statusproperty#

status: ReportStatus

Return aggregate status, preserving execution errors distinctly.

combinemethodclassmethod#

def combine(*reports: ValidationReport) -> ValidationReport

Combine reports in argument order, rejecting duplicate check IDs.

from_errorsmethodclassmethod#

def from_errors(errors: Mapping[str, tuple[Scope, Exception]]) -> ValidationReport

Compose captured execution errors without retrying the checks.

from_outcomesmethodclassmethod#

def from_outcomes(outcomes: Mapping[str, tuple[Scope, ExpectationOutcome]]) -> ValidationReport

Compose 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#

class 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: Column

nameattributeinstance attribute#

name: str

null_policyattributeclass attributeinstance attribute#

null_policy: NullPolicy = 'fail'

predicatemethod#

def predicate() -> Column

Return a boolean Column with the configured NULL policy applied.