Skip to content

v2.12.0 — Validation rules and statistical drift

Latest

Choose a tag to compare

@devlprkhan devlprkhan released this 23 Nov 11:41
· 6 commits to main since this release
e31a07f

2.12.0 is the validation and statistical-drift release. It adds a composable rule layer on top of the existing validation report, reference-versus-current drift comparison, bounded failing-row diagnostics, and an append-only report sink for batch history.

Added

  • Statistical drift: DriftPolicy, DriftProfile, DistributionDriftReport, and compare_distributions() compare a current batch against a stored reference using population stability index (PSI), an approximate 1-D Wasserstein distance plus a scale-free ratio, missingness deltas, and category share deltas. Levels outside the retained reference categories are aggregated into an other bucket. Numeric and datetime columns are supported; booleans compare as categorical.
  • Documented thresholds: PSI 0.10 warning / 0.25 error, 5 pp missingness warning, 10 pp category warning, an optional Wasserstein ratio threshold, and min_sample=20, which downgrades errors to warnings on small batches. Thresholds must be finite and non-negative, counts must be integers, and policies serialize to and from JSON.
  • Portable profiles: DriftProfile.from_frame() keeps a bounded, JSON-serializable summary (bin edges, shares, scales, 512 midpoint quantiles per numeric column, and the top 20 levels per categorical column) instead of a sorted raw column. to_json() / from_json() round-trip the profile and its policy, and the default repr is redacted.
  • Composable rules: col() conditions with explicit .eq, .ne, .lt, .le, .gt, .ge, .isin, .not_in, .between, .isna, .notna, and .matches methods; &, |, and ~ composition; row_rule() for cross-column predicates; conditional() for scoped rules; grouped() for per-group checks; unique_combination(); and sum_equals(). Comparisons skip missing operands, so nulls do not fail a predicate unless it asks for them with .isna().
  • Public Validatable protocol: validate() accepts expectations, rules, custom objects with name, column, severity, and check(frame), and mixed lists. A custom rule may return several ValidationResult objects from one check.
  • Bounded diagnostics: ValidationReport.diagnose(frame, limit=5, include_values=False, include_index=True, max_value_length=32) samples failing rows as RowDiagnostics — bounded per failing rule, value-free by default, truncated values when enabled, and only failing frame-level or grouped rules listed in skipped.
  • Batch history: JsonlReportSink appends CleanerReport, DistributionDriftReport, or mapping records to a JSON Lines file, reads them back in order, summarizes history, and exposes drift_against_previous(), which reuses the stored reference profile and policy for a reproducible comparison.

Changed

  • ValidationReport gains sources and from_results(..., sources=...) so diagnostics can attribute failures. Reports built from contract findings have no sources and produce an empty diagnostic sample.
  • JSON-safe conversion is shared by reporting, drift, and sinks; drift profiles and reports serialize NaN and infinity as null and leak no non-standard JSON literals.
  • DriftProfile requires a non-empty reference and current frame with unique string column labels, reports missing or kind-changed columns as errors with metrics skipped, and never mutates the caller's frames.
  • sum_equals() fails rows with present non-numeric components or targets instead of silently skipping them, and JsonlReportSink reads records with split("\n") so Unicode line separators in metadata cannot corrupt history.

Integration boundary

This release integrates with Pandera, Feature-engine, and Evidently rather than rebuilding them: rules and drift operate on plain pandas frames, so existing contract and monitoring stacks can keep their own semantics.

Documentation

Compatibility

Python 3.10–3.13, pandas 2.x and 3.x. No new runtime dependencies.

Full changelog: https://github.com/devlprkhan/universal-data-cleaner/blob/main/CHANGELOG.md