Artifacts & reproducibility
A fitted cleaner is only useful if the next process can prove it is using the same rules. This page covers the audit trail, manifests, fingerprints, and saved artifacts that make that possible.
Every learned or configured rule is recorded during fit():
log = cleaner.decision_log()
log[log["action"] == "cap_outliers"]The columns are:
| Column | Meaning |
|---|---|
column | The source column |
action | What happened, such as impute or cap_outliers |
reason | Why it happened |
source | learned, config, contract, or inferred |
before | The value before the decision, when relevant |
after | The value after the decision, when relevant |
Typical actions include impute, cap_outliers, expand_datetime, add_missing_indicator, drop_column, and unseen_category_policy.
The log is a tidy DataFrame, so it can be shipped to an experiment tracker or compared between two model versions.
to_manifest() builds a JSON-serializable description of the fitted cleaner:
import json
manifest = cleaner.to_manifest(X_train, include_fingerprint=True)
print(json.dumps(manifest, indent=2))The manifest contains:
- library and artifact versions
- pandas, numpy, and scikit-learn versions
- the cleaner configuration and contract
- the input schema and output columns
- fitted state and the decision log
- an optional training fingerprint
- a UTC timestamp
Use include_fingerprint=True when you want lineage without storing the data. Set CleanerConfig(fingerprint_on_fit=True) to compute the training fingerprint once during fit(), so to_manifest() needs no data later.
cleaner.save("artifacts/data_cleaner.joblib")
restored = DataCleaner.load("artifacts/data_cleaner.joblib")
X_new_clean = restored.transform(X_new)save() embeds the manifest and the training fingerprint in the artifact. It writes to a temporary file in the destination directory, reads the file back to validate it, and then atomically replaces the target with os.replace. A failed or interrupted save leaves the previous artifact intact and removes the partial file. load() refuses artifacts written by an incompatible artifact format or library major version and raises ArtifactCompatibilityError. The artifact format for the 2.x line is 2.
The manifest also records the pandas, NumPy, and scikit-learn versions used to write the artifact. If a major version differs at load time, load() logs a warning by default. Promote that warning to an error when a mismatched runtime must never load the artifact:
restored = DataCleaner.load(
"artifacts/data_cleaner.joblib",
strict_environment=True,
)If you have deliberately accepted the risk, load an incompatible artifact with a warning:
restored = DataCleaner.load(
"artifacts/data_cleaner.joblib",
allow_incompatible=True,
)verify_version=False skips the compatibility check entirely. Artifacts are restored with joblib, which uses pickle; only load files you trust.
We evaluated skops.io for untrusted artifacts. It requires converting every nested object through a trusted-type allowlist and does not transparently cover the full pandas and scikit-learn state stored in a cleaner. Adding it as a runtime dependency would break the library’s dependency-light guarantee, so the 2.x line continues to use joblib and documents the trust boundary: treat artifacts as code, store them in a controlled location, and never load a file from an untrusted source.
Use artifact_manifest() on a loaded cleaner to inspect what was stored:
restored.artifact_manifest()A fingerprint is a stable SHA-256 hash of the schema plus summary statistics. It never hashes raw values, so it is safe to log and compare across systems.
from data_cleaner import (
assert_schema_stable,
compare_fingerprints,
fingerprint_dataframe,
)
expected = fingerprint_dataframe(X_train)
actual = fingerprint_dataframe(X_new)
same = compare_fingerprints(expected, actual)
assert_schema_stable(X_new, expected) # raises ValueError on schema/stat driftUse fingerprints to:
- verify a batch still has the expected schema and rough distribution
- detect accidental changes between training and serving
- store a compact lineage marker next to a model
Fingerprints are not a substitute for a contract. They summarize; a contract states what is allowed.
A reproducible model artifact usually contains:
artifacts/branchdata_cleaner.joblib # fitted cleaner + embedded manifestbranchcontract.json # reviewable schema and rolesbranchmanifest.json # optional external copy for the model registrycleaner.save("artifacts/data_cleaner.joblib")
contract.to_json() # write this to artifacts/contract.json
manifest = cleaner.to_manifest(X_train, include_fingerprint=True)- The package version is exposed as
data_cleaner.__version__. - The artifact format version is separate and remains
2for the 2.x line. load()checks the artifact version by default.- A contract or configuration change can change the manifest without changing the artifact format.
- Contracts & drift for the schema rules referenced by manifests.
- Batch reporting for reviewing decisions, drift, and validation together.
- Production guide for how to use these artifacts safely.
- API reference for the exact method signatures.