universal-data-cleaner 2.6.0__tar.gz → 2.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/PKG-INFO +19 -4
  2. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/README.md +16 -3
  3. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/pyproject.toml +8 -1
  4. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/__init__.py +9 -1
  5. universal_data_cleaner-2.8.0/src/data_cleaner/__main__.py +188 -0
  6. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/_version.py +1 -1
  7. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/ingestion.py +412 -82
  8. universal_data_cleaner-2.8.0/src/data_cleaner/reporting.py +661 -0
  9. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/universal_data_cleaner.egg-info/PKG-INFO +19 -4
  10. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/universal_data_cleaner.egg-info/SOURCES.txt +5 -0
  11. universal_data_cleaner-2.8.0/src/universal_data_cleaner.egg-info/entry_points.txt +2 -0
  12. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/universal_data_cleaner.egg-info/requires.txt +3 -0
  13. universal_data_cleaner-2.8.0/tests/test_excel_ingestion.py +443 -0
  14. universal_data_cleaner-2.8.0/tests/test_reporting.py +319 -0
  15. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/LICENSE +0 -0
  16. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/setup.cfg +0 -0
  17. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/_roles.py +0 -0
  18. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/artifacts.py +0 -0
  19. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/cleaner.py +0 -0
  20. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/config.py +0 -0
  21. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/contract.py +0 -0
  22. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/decisions.py +0 -0
  23. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/integration.py +0 -0
  24. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/ml_audit.py +0 -0
  25. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/profiling.py +0 -0
  26. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/py.typed +0 -0
  27. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/data_cleaner/validation.py +0 -0
  28. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/universal_data_cleaner.egg-info/dependency_links.txt +0 -0
  29. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/src/universal_data_cleaner.egg-info/top_level.txt +0 -0
  30. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/tests/test_data_cleaner.py +0 -0
  31. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/tests/test_ingestion.py +0 -0
  32. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/tests/test_ml_audit.py +0 -0
  33. {universal_data_cleaner-2.6.0 → universal_data_cleaner-2.8.0}/tests/test_validation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: universal-data-cleaner
3
- Version: 2.6.0
3
+ Version: 2.8.0
4
4
  Summary: Production-ready, scikit-learn-compatible data cleaning transformer for pandas.
5
5
  Author: Haseeb Khan
6
6
  License-Expression: MIT
@@ -30,6 +30,8 @@ Requires-Dist: pandas>=2.2
30
30
  Requires-Dist: numpy>=1.26
31
31
  Requires-Dist: scikit-learn>=1.4
32
32
  Requires-Dist: joblib>=1.3
33
+ Provides-Extra: excel
34
+ Requires-Dist: openpyxl>=3.1; extra == "excel"
33
35
  Dynamic: license-file
34
36
 
35
37
  # Universal Data Cleaner
@@ -58,7 +60,8 @@ The docs site is the central reference. This README is the short entry point.
58
60
  | [Leak-safe workflow](https://devlprkhan.github.io/universal-data-cleaner/leak-safe-workflow/) | The fit/transform contract and common mistakes |
59
61
  | [Cleaning data](https://devlprkhan.github.io/universal-data-cleaner/cleaning/) | Config, roles, imputation, outliers, datetimes |
60
62
  | [Contracts & drift](https://devlprkhan.github.io/universal-data-cleaner/contracts/) | `ColumnSpec`, `DataContract`, drift checks |
61
- | [Safe ingestion](https://devlprkhan.github.io/universal-data-cleaner/ingestion/) | Contract-driven CSV reads and ingestion reports |
63
+ | [Safe ingestion](https://devlprkhan.github.io/universal-data-cleaner/ingestion/) | Contract-driven CSV and Excel reads with ingestion reports |
64
+ | [Batch reporting](https://devlprkhan.github.io/universal-data-cleaner/reporting/) | `CleanerReport` and the `data-cleaner audit` CLI |
62
65
  | [Validation, joins & dedup](https://devlprkhan.github.io/universal-data-cleaner/validation-joins/) | Expectations, join diagnostics, integrity, dedup |
63
66
  | [ML split audit](https://devlprkhan.github.io/universal-data-cleaner/ml-split-audit/) | Duplicate, group, temporal, and target leakage |
64
67
  | [Artifacts & reproducibility](https://devlprkhan.github.io/universal-data-cleaner/artifacts/) | Decision log, manifests, fingerprints, save/load |
@@ -80,6 +83,16 @@ uv add universal-data-cleaner
80
83
  The distribution name is `universal-data-cleaner`; the import name is
81
84
  `data_cleaner`.
82
85
 
86
+ For Excel input, install the optional extra:
87
+
88
+ ```bash
89
+ pip install "universal-data-cleaner[excel]"
90
+ ```
91
+
92
+ ```bash
93
+ uv add "universal-data-cleaner[excel]"
94
+ ```
95
+
83
96
  ```python
84
97
  from data_cleaner import CleanerConfig, DataCleaner
85
98
  ```
@@ -133,8 +146,10 @@ for the full explanation.
133
146
  - boolean coercion and imputation
134
147
  - datetime parsing plus calendar feature extraction
135
148
  - optional missing-value indicators and constant-column dropping
136
- - safe CSV ingestion with contract-driven coercion, identifier protection, date
137
- and boolean guards, and an audit report
149
+ - safe CSV and Excel ingestion with contract-driven coercion, identifier
150
+ protection, date and boolean guards, and an audit report
151
+ - `CleanerReport` combining profile, contract drift, validation, ingestion, and
152
+ cleaner decisions, plus a `data-cleaner audit` CLI
138
153
  - declarative contracts with roles, allowed values, ranges, patterns, and uniqueness
139
154
  - automatic train-schema contract inference and transform-time drift reports
140
155
  - expectation checks and validation reports
@@ -24,7 +24,8 @@ The docs site is the central reference. This README is the short entry point.
24
24
  | [Leak-safe workflow](https://devlprkhan.github.io/universal-data-cleaner/leak-safe-workflow/) | The fit/transform contract and common mistakes |
25
25
  | [Cleaning data](https://devlprkhan.github.io/universal-data-cleaner/cleaning/) | Config, roles, imputation, outliers, datetimes |
26
26
  | [Contracts & drift](https://devlprkhan.github.io/universal-data-cleaner/contracts/) | `ColumnSpec`, `DataContract`, drift checks |
27
- | [Safe ingestion](https://devlprkhan.github.io/universal-data-cleaner/ingestion/) | Contract-driven CSV reads and ingestion reports |
27
+ | [Safe ingestion](https://devlprkhan.github.io/universal-data-cleaner/ingestion/) | Contract-driven CSV and Excel reads with ingestion reports |
28
+ | [Batch reporting](https://devlprkhan.github.io/universal-data-cleaner/reporting/) | `CleanerReport` and the `data-cleaner audit` CLI |
28
29
  | [Validation, joins & dedup](https://devlprkhan.github.io/universal-data-cleaner/validation-joins/) | Expectations, join diagnostics, integrity, dedup |
29
30
  | [ML split audit](https://devlprkhan.github.io/universal-data-cleaner/ml-split-audit/) | Duplicate, group, temporal, and target leakage |
30
31
  | [Artifacts & reproducibility](https://devlprkhan.github.io/universal-data-cleaner/artifacts/) | Decision log, manifests, fingerprints, save/load |
@@ -46,6 +47,16 @@ uv add universal-data-cleaner
46
47
  The distribution name is `universal-data-cleaner`; the import name is
47
48
  `data_cleaner`.
48
49
 
50
+ For Excel input, install the optional extra:
51
+
52
+ ```bash
53
+ pip install "universal-data-cleaner[excel]"
54
+ ```
55
+
56
+ ```bash
57
+ uv add "universal-data-cleaner[excel]"
58
+ ```
59
+
49
60
  ```python
50
61
  from data_cleaner import CleanerConfig, DataCleaner
51
62
  ```
@@ -99,8 +110,10 @@ for the full explanation.
99
110
  - boolean coercion and imputation
100
111
  - datetime parsing plus calendar feature extraction
101
112
  - optional missing-value indicators and constant-column dropping
102
- - safe CSV ingestion with contract-driven coercion, identifier protection, date
103
- and boolean guards, and an audit report
113
+ - safe CSV and Excel ingestion with contract-driven coercion, identifier
114
+ protection, date and boolean guards, and an audit report
115
+ - `CleanerReport` combining profile, contract drift, validation, ingestion, and
116
+ cleaner decisions, plus a `data-cleaner audit` CLI
104
117
  - declarative contracts with roles, allowed values, ranges, patterns, and uniqueness
105
118
  - automatic train-schema contract inference and transform-time drift reports
106
119
  - expectation checks and validation reports
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "universal-data-cleaner"
7
- version = "2.6.0"
7
+ version = "2.8.0"
8
8
  description = "Production-ready, scikit-learn-compatible data cleaning transformer for pandas."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -43,6 +43,9 @@ dependencies = [
43
43
  "joblib>=1.3",
44
44
  ]
45
45
 
46
+ [project.optional-dependencies]
47
+ excel = ["openpyxl>=3.1"]
48
+
46
49
  [project.urls]
47
50
  Homepage = "https://github.com/devlprkhan/universal-data-cleaner"
48
51
  Documentation = "https://devlprkhan.github.io/universal-data-cleaner/"
@@ -50,6 +53,9 @@ Repository = "https://github.com/devlprkhan/universal-data-cleaner"
50
53
  Issues = "https://github.com/devlprkhan/universal-data-cleaner/issues"
51
54
  Changelog = "https://github.com/devlprkhan/universal-data-cleaner/blob/main/CHANGELOG.md"
52
55
 
56
+ [project.scripts]
57
+ data-cleaner = "data_cleaner.__main__:main"
58
+
53
59
  [dependency-groups]
54
60
  docs = [
55
61
  "mkdocs-material>=9.5",
@@ -61,6 +67,7 @@ dev = [
61
67
  "mypy>=2.4.0",
62
68
  "nbclient>=0.11.0",
63
69
  "nbformat>=5.11.1",
70
+ "openpyxl>=3.1",
64
71
  "pandas-stubs>=2.3.3.260113",
65
72
  "pre-commit>=4.6.2",
66
73
  "pytest>=9.1.1",
@@ -22,7 +22,12 @@ from .cleaner import DataCleaner
22
22
  from .config import CleanerConfig
23
23
  from .contract import ColumnSpec, Contract, DataContract, DriftReport
24
24
  from .decisions import CleaningDecision
25
- from .ingestion import IngestionError, IngestionReport, read_csv_safe
25
+ from .ingestion import (
26
+ IngestionError,
27
+ IngestionReport,
28
+ read_csv_safe,
29
+ read_excel_safe,
30
+ )
26
31
  from .integration import (
27
32
  DeduplicationReport,
28
33
  JoinDiagnosis,
@@ -38,6 +43,7 @@ from .profiling import (
38
43
  drop_duplicate_rows,
39
44
  profile_dataframe,
40
45
  )
46
+ from .reporting import CleanerReport
41
47
  from .validation import (
42
48
  Expectation,
43
49
  ValidationReport,
@@ -54,6 +60,7 @@ from .validation import (
54
60
 
55
61
  __all__ = [
56
62
  "CleanerConfig",
63
+ "CleanerReport",
57
64
  "CleaningDecision",
58
65
  "ColumnSpec",
59
66
  "Contract",
@@ -87,6 +94,7 @@ __all__ = [
87
94
  "not_null",
88
95
  "profile_dataframe",
89
96
  "read_csv_safe",
97
+ "read_excel_safe",
90
98
  "row_count_between",
91
99
  "unique",
92
100
  "validate",
@@ -0,0 +1,188 @@
1
+ """Command-line entry point for local batch audits."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import sys
7
+ import zipfile
8
+ from pathlib import Path
9
+
10
+ import pandas as pd
11
+
12
+ from ._version import __version__
13
+ from .cleaner import DataCleaner
14
+ from .contract import DataContract
15
+ from .ingestion import IngestionReport, read_csv_safe, read_excel_safe
16
+ from .reporting import CleanerReport
17
+
18
+ _EXCEL_SUFFIXES = {".xls", ".xlsb", ".xlsm", ".xlsx", ".ods"}
19
+
20
+
21
+ def build_parser() -> argparse.ArgumentParser:
22
+ """Build the ``python -m data_cleaner`` argument parser."""
23
+ parser = argparse.ArgumentParser(
24
+ prog="data-cleaner",
25
+ description="Leak-safe data cleaning and batch audits.",
26
+ )
27
+ parser.add_argument(
28
+ "--version",
29
+ action="version",
30
+ version=f"%(prog)s {__version__}",
31
+ )
32
+ subparsers = parser.add_subparsers(dest="command", required=True)
33
+
34
+ audit = subparsers.add_parser(
35
+ "audit",
36
+ help="Audit a CSV or Excel batch and print a report.",
37
+ description=(
38
+ "Read a CSV or Excel file safely, then report its profile, contract "
39
+ "findings, and cleaner decisions."
40
+ ),
41
+ )
42
+ audit.add_argument("path", type=Path, help="CSV or Excel file to audit.")
43
+ sheet = audit.add_mutually_exclusive_group()
44
+ sheet.add_argument(
45
+ "--sheet",
46
+ default=None,
47
+ metavar="NAME",
48
+ help=(
49
+ "Excel worksheet name (defaults to the first sheet); only valid for "
50
+ "Excel input."
51
+ ),
52
+ )
53
+ sheet.add_argument(
54
+ "--sheet-index",
55
+ type=int,
56
+ default=None,
57
+ metavar="N",
58
+ help=(
59
+ "Zero-based Excel worksheet index; only valid for Excel input and "
60
+ "mutually exclusive with --sheet."
61
+ ),
62
+ )
63
+ source = audit.add_mutually_exclusive_group()
64
+ source.add_argument(
65
+ "--contract",
66
+ type=Path,
67
+ help="JSON contract file used for ingestion and drift checks.",
68
+ )
69
+ source.add_argument(
70
+ "--cleaner",
71
+ type=Path,
72
+ help="Fitted DataCleaner artifact; uses its contract and decisions.",
73
+ )
74
+ audit.add_argument(
75
+ "--name",
76
+ default=None,
77
+ help="Dataset name shown in the profile (defaults to the file stem).",
78
+ )
79
+ audit.add_argument(
80
+ "--format",
81
+ choices=("markdown", "json"),
82
+ default="markdown",
83
+ help="Report format written to stdout or --output.",
84
+ )
85
+ audit.add_argument(
86
+ "--output",
87
+ type=Path,
88
+ default=None,
89
+ help="Write the report to this file instead of stdout.",
90
+ )
91
+ audit.add_argument(
92
+ "--no-profile",
93
+ action="store_true",
94
+ help="Skip the column-level profile for faster large-file audits.",
95
+ )
96
+ audit.add_argument(
97
+ "--fail-on-warning",
98
+ action="store_true",
99
+ help="Exit with status 1 when warnings are present.",
100
+ )
101
+ return parser
102
+
103
+
104
+ def _load_contract(path: Path) -> DataContract:
105
+ return DataContract.from_json(path.read_text(encoding="utf-8"))
106
+
107
+
108
+ def _read_input(
109
+ path: Path, contract: DataContract | None, sheet: str | int | None
110
+ ) -> tuple[pd.DataFrame, IngestionReport]:
111
+ """Read a CSV or Excel input and return its ingestion report."""
112
+ if path.suffix.lower() in _EXCEL_SUFFIXES:
113
+ frame, ingestion = read_excel_safe(
114
+ path,
115
+ contract=contract,
116
+ sheet_name=0 if sheet is None else sheet,
117
+ on_error="ignore",
118
+ )
119
+ return frame, ingestion
120
+ if sheet is not None:
121
+ raise ValueError("--sheet is only valid for Excel input")
122
+ frame, ingestion = read_csv_safe(path, contract=contract, on_error="ignore")
123
+ return frame, ingestion
124
+
125
+
126
+ def _run_audit(args: argparse.Namespace) -> int:
127
+ contract: DataContract | None = None
128
+ cleaner: DataCleaner | None = None
129
+ if args.contract is not None:
130
+ contract = _load_contract(args.contract)
131
+ if args.cleaner is not None:
132
+ cleaner = DataCleaner.load(args.cleaner)
133
+ contract = cleaner.fitted_contract()
134
+
135
+ sheet = args.sheet if args.sheet is not None else args.sheet_index
136
+ frame, ingestion = _read_input(args.path, contract, sheet)
137
+ dataset_name = args.name or args.path.stem
138
+ if cleaner is not None:
139
+ report = CleanerReport.from_cleaner(
140
+ cleaner,
141
+ frame,
142
+ source=ingestion.source,
143
+ name=dataset_name,
144
+ ingestion=ingestion,
145
+ include_profile=not args.no_profile,
146
+ )
147
+ else:
148
+ report = CleanerReport.from_frame(
149
+ frame,
150
+ source=ingestion.source,
151
+ name=dataset_name,
152
+ contract=contract,
153
+ ingestion=ingestion,
154
+ include_profile=not args.no_profile,
155
+ )
156
+
157
+ rendered = (
158
+ report.to_markdown()
159
+ if args.format == "markdown"
160
+ else report.to_json(indent=2) + "\n"
161
+ )
162
+ if args.output is None:
163
+ print(rendered, end="")
164
+ else:
165
+ args.output.parent.mkdir(parents=True, exist_ok=True)
166
+ args.output.write_text(rendered, encoding="utf-8")
167
+ print(f"Wrote {args.format} report to {args.output}", file=sys.stderr)
168
+
169
+ failed = not report.success or (args.fail_on_warning and report.has_warnings)
170
+ return 1 if failed else 0
171
+
172
+
173
+ def main(argv: list[str] | None = None) -> int:
174
+ """Run the CLI and return a process exit status."""
175
+ parser = build_parser()
176
+ args = parser.parse_args(argv)
177
+ if args.command == "audit":
178
+ try:
179
+ return _run_audit(args)
180
+ except (ImportError, OSError, TypeError, ValueError, zipfile.BadZipFile) as exc:
181
+ print(f"error: {exc}", file=sys.stderr)
182
+ return 2
183
+ parser.print_help()
184
+ return 2
185
+
186
+
187
+ if __name__ == "__main__": # pragma: no cover - exercised via `python -m`
188
+ raise SystemExit(main())
@@ -1,4 +1,4 @@
1
1
  """Single source of truth for the package version."""
2
2
 
3
- __version__ = "2.6.0"
3
+ __version__ = "2.8.0"
4
4
  _ARTIFACT_VERSION = 2