Skip to content
Build a report from a DataFrame

Batch reporting

`CleanerReport` answers three questions about one batch in a single object: what does it look like, what changed, and should it reach the model? It composes profiling, contract drift, validation, ingestion, and the cleaner's decision log without transforming the data.

Python
from data_cleaner import CleanerReport

report = CleanerReport.from_frame(batch, source="validation_batch")

print(report.summary())
print(report.findings)

The frame is never modified. from_frame() reads the batch, records dataset and column metrics, and emits warning-severity findings for common profile problems:

FindingMeaning
empty_datasetThe batch has no rows or no columns
empty_columnA column has no non-null values
constant_columnA column has a single distinct value
high_missingMissingness is at or above high_missing_threshold (default 50%)
duplicate_rowsThe batch contains exact duplicate rows

Disable profiling entirely for very large batches:

Python
report = CleanerReport.from_frame(batch, include_profile=False)

Or change the missingness threshold:

Python
report = CleanerReport.from_frame(batch, high_missing_threshold=20)
report = CleanerReport.from_frame(batch, high_missing_threshold=None)  # disable

Python
report = CleanerReport.from_frame(
    batch,
    contract=contract,
    expectations=[not_null("customer_id"), between("age", 0, 120)],
)

Contract and expectation failures become error-severity findings. Warnings do not fail the batch:

Python
report.success  # False only when an error-severity finding exists
report.errors  # DataFrame of error findings
report.warnings  # DataFrame of warning findings
report.raise_if_failed("Batch rejected")

Python
from data_cleaner import CleanerReport

report = CleanerReport.from_csv("incoming.csv", contract=contract)
report = CleanerReport.from_excel(
    "incoming.xlsx",
    contract=contract,
    sheet_name="Orders",
)

from_csv() and from_excel() read through read_csv_safe() and read_excel_safe() and attach the resulting IngestionReport, so ingestion findings appear alongside contract and profile findings. They default to on_error="ignore" so a report is always returned; error findings still make report.success false. Pass on_error="raise" to stop at the first unparseable value instead.

Excel support requires the optional excel extra:

Terminal
pip install "universal-data-cleaner[excel]"

Python
report = CleanerReport.from_cleaner(cleaner, batch, source="production")

The fitted contract supplies the drift section and the cleaner’s decision log is attached. The cleaner is not re-fitted and the batch is not transformed.

Every finding has the same columns:

ColumnMeaning
sourceprofile, contract, validation, or ingestion
columnAffected column, or * for dataset-level findings
checkMachine-readable check name, for example missing_column
severityerror or warning
messageHuman-readable explanation
countRows or occurrences affected

Findings are de-duplicated per (column, check, severity) and sorted by severity. The whole report renders consistently:

Python
report.to_markdown()  # overview, findings, profile, contract, validation, ingestion, decisions
report.to_dict()  # JSON-friendly structure
report.to_json(indent=2)

Reports contain column names, counts, and messages, never raw cell values, so they are safe to log or attach to a build artifact.

The same report is available from the terminal:

Terminal
python -m data_cleaner audit incoming.csv
python -m data_cleaner audit incoming.xlsx --sheet Orders

The installed console script is equivalent:

Terminal
data-cleaner audit incoming.xlsx --sheet Orders

The command detects CSV and Excel input from the file extension. Common options:

OptionEffect
--contract contract.jsonRead under DataContract.from_json() and check drift
--cleaner cleaner.joblibLoad a fitted cleaner and use its contract and decisions
--sheet NAMEExcel worksheet to audit by name (defaults to the first sheet)
--sheet-index NExcel worksheet to audit by zero-based index
--name NAMEDataset name in the profile (defaults to the file stem)
--format markdown\|jsonOutput format written to stdout or --output
--output PATHWrite the report to a file instead of stdout
--no-profileSkip the column profile for faster large-file audits
--fail-on-warningTreat warnings as a failing exit status

--contract and --cleaner are mutually exclusive. --sheet and --sheet-index are mutually exclusive, accept only non-negative indices, and are valid only for Excel input.

CodeMeaning
0The report succeeded
1Error findings exist, or warnings exist with --fail-on-warning
2The input could not be read, a contract/artifact could not be loaded, or a spreadsheet engine is missing

Use the exit code in CI or a pre-model gate:

Terminal
python -m data_cleaner audit incoming.csv \
  --contract artifacts/contract.json \
  --format json \
  --output artifacts/audit.json \
  --fail-on-warning

  • It does not fit or transform. Call cleaner.transform() separately when the batch passes review.
  • It does not install optional spreadsheet engines. Install the excel extra for .xlsx and .xlsm, or another pandas engine for legacy formats.
  • It cannot recover leading zeros that Excel already discarded when an ID was stored as a number. Store identifiers as text in the workbook.
  • It does not replace the cleaner’s own drift policy. on_drift still controls transform(); the report is a review layer around it.