universal-data-cleaner 2.3.0__tar.gz → 2.5.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.
- {universal_data_cleaner-2.3.0/src/universal_data_cleaner.egg-info → universal_data_cleaner-2.5.0}/PKG-INFO +172 -2
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/README.md +171 -1
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/pyproject.toml +1 -1
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/__init__.py +43 -1
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/_version.py +1 -1
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/contract.py +19 -0
- universal_data_cleaner-2.5.0/src/data_cleaner/integration.py +613 -0
- universal_data_cleaner-2.5.0/src/data_cleaner/ml_audit.py +1212 -0
- universal_data_cleaner-2.5.0/src/data_cleaner/validation.py +581 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0/src/universal_data_cleaner.egg-info}/PKG-INFO +172 -2
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/universal_data_cleaner.egg-info/SOURCES.txt +6 -1
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/tests/test_data_cleaner.py +18 -0
- universal_data_cleaner-2.5.0/tests/test_ml_audit.py +765 -0
- universal_data_cleaner-2.5.0/tests/test_validation.py +399 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/LICENSE +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/setup.cfg +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/_roles.py +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/artifacts.py +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/cleaner.py +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/config.py +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/decisions.py +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/profiling.py +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/data_cleaner/py.typed +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/universal_data_cleaner.egg-info/dependency_links.txt +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/universal_data_cleaner.egg-info/requires.txt +0 -0
- {universal_data_cleaner-2.3.0 → universal_data_cleaner-2.5.0}/src/universal_data_cleaner.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: universal-data-cleaner
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0
|
|
4
4
|
Summary: Production-ready, scikit-learn-compatible data cleaning transformer for pandas.
|
|
5
5
|
Author: Haseeb Khan
|
|
6
6
|
License-Expression: MIT
|
|
@@ -73,6 +73,7 @@ breaks at inference time because the median is recomputed on the new batch.
|
|
|
73
73
|
- automatic train-schema contract inference and transform-time drift reports
|
|
74
74
|
- `on_drift` policy: `raise`, `warn`, or `ignore`
|
|
75
75
|
- identifier columns that are never numeric-coerced, median-imputed, or capped
|
|
76
|
+
- train/test split audits for duplicate, group, temporal, and target leakage
|
|
76
77
|
- joblib save / load with artifact versioning
|
|
77
78
|
- scikit-learn `Pipeline`, `clone`, and `get_feature_names_out` compatibility
|
|
78
79
|
|
|
@@ -241,6 +242,152 @@ restored = DataContract.from_json(payload)
|
|
|
241
242
|
# restored = DataContract.from_yaml(contract.to_yaml())
|
|
242
243
|
```
|
|
243
244
|
|
|
245
|
+
## Expectations, joins, and referential integrity
|
|
246
|
+
|
|
247
|
+
### Expectations and validation reports
|
|
248
|
+
|
|
249
|
+
Run lightweight expectations against any batch and get a shareable report:
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from data_cleaner import (
|
|
253
|
+
between,
|
|
254
|
+
has_dtype,
|
|
255
|
+
in_set,
|
|
256
|
+
matches_pattern,
|
|
257
|
+
not_null,
|
|
258
|
+
row_count_between,
|
|
259
|
+
unique,
|
|
260
|
+
validate,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
report = validate(
|
|
264
|
+
orders_new,
|
|
265
|
+
[
|
|
266
|
+
not_null("order_id"),
|
|
267
|
+
unique("order_id"),
|
|
268
|
+
in_set("status", ["new", "paid", "shipped"]),
|
|
269
|
+
between("amount", 0, 100_000),
|
|
270
|
+
matches_pattern("email", r"[^@]+@[^@]+\.[^@]+"),
|
|
271
|
+
has_dtype("created_at", "datetime"),
|
|
272
|
+
row_count_between(min_rows=1),
|
|
273
|
+
],
|
|
274
|
+
)
|
|
275
|
+
print(report.to_markdown())
|
|
276
|
+
report.raise_if_failed()
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
`report.success` is true when no error-severity expectation failed.
|
|
280
|
+
`report.failures` includes warnings too, so use `severity="warning"` for soft
|
|
281
|
+
checks. `has_dtype` accepts broad kinds (`numeric`, `categorical`, `boolean`,
|
|
282
|
+
`datetime`) or an exact pandas dtype such as `float64`.
|
|
283
|
+
|
|
284
|
+
Contracts can validate a batch directly and return the same report type:
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
from data_cleaner import DataContract
|
|
288
|
+
|
|
289
|
+
contract = DataContract.from_frame(orders_train)
|
|
290
|
+
result = contract.validate(orders_new)
|
|
291
|
+
result.failures.to_markdown()
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
`Contract` is a shorthand alias for `DataContract`.
|
|
295
|
+
|
|
296
|
+
### Join diagnostics
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
from data_cleaner import diagnose_join
|
|
300
|
+
|
|
301
|
+
report = diagnose_join(orders, customers, on="customer_id", how="left")
|
|
302
|
+
|
|
303
|
+
report.safe # False on cardinality mismatch, left/right row multiplication, or null keys
|
|
304
|
+
report.cardinality # e.g. "1:m"
|
|
305
|
+
report.row_multiplier # output rows / left rows
|
|
306
|
+
report.unmatched_left
|
|
307
|
+
report.unmatched_right
|
|
308
|
+
report.warnings
|
|
309
|
+
report.raise_if_unsafe()
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
`diagnose_join` defaults to `how="left"` and `validate="1:1"`. It reports
|
|
313
|
+
duplicate keys, null keys, unmatched rows, and the actual output row count
|
|
314
|
+
without materializing the full joined frame.
|
|
315
|
+
|
|
316
|
+
### Referential integrity
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
from data_cleaner import check_referential_integrity
|
|
320
|
+
|
|
321
|
+
report = check_referential_integrity(
|
|
322
|
+
orders, customers, child_key="customer_id", parent_key="id"
|
|
323
|
+
)
|
|
324
|
+
report.orphan_rows
|
|
325
|
+
report.orphan_keys
|
|
326
|
+
report.raise_if_invalid()
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Null child keys are reported but allowed by default (`allow_null_keys=True`).
|
|
330
|
+
Duplicate parent keys make the relationship invalid because the parent key is
|
|
331
|
+
not a unique reference target.
|
|
332
|
+
|
|
333
|
+
### Business-key deduplication
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
from data_cleaner import deduplicate_by_business_key
|
|
337
|
+
|
|
338
|
+
deduped, report = deduplicate_by_business_key(
|
|
339
|
+
orders, key="order_id", keep="last", tie_breaker="updated_at"
|
|
340
|
+
)
|
|
341
|
+
report.removed_rows
|
|
342
|
+
report.removed # the actual rows that were dropped
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
The returned frame preserves the input row order and index. `tie_breaker`
|
|
346
|
+
prefers non-null values, and null business keys are reported explicitly.
|
|
347
|
+
The input frame is never mutated.
|
|
348
|
+
|
|
349
|
+
## ML split audits
|
|
350
|
+
|
|
351
|
+
Audit a train/test split for contamination and distribution surprises before
|
|
352
|
+
training:
|
|
353
|
+
|
|
354
|
+
```python
|
|
355
|
+
from data_cleaner import audit_split
|
|
356
|
+
|
|
357
|
+
audit = audit_split(
|
|
358
|
+
X_train,
|
|
359
|
+
X_test,
|
|
360
|
+
y_train,
|
|
361
|
+
y_test,
|
|
362
|
+
groups=groups, # combined train+test labels, or pass groups_test=
|
|
363
|
+
time_col="event_time",
|
|
364
|
+
id_cols=["customer_id"],
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
audit.valid # False when an error-severity finding exists
|
|
368
|
+
audit.findings # check, column, severity, message, train, test
|
|
369
|
+
audit.summary()
|
|
370
|
+
audit.to_markdown()
|
|
371
|
+
audit.raise_if_invalid()
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Schema problems such as missing columns, empty splits, exact duplicate overlap,
|
|
375
|
+
group leakage, temporal leakage, and unparseable or numeric timestamps are
|
|
376
|
+
errors. Near-duplicates, constant / near-constant columns, high-cardinality
|
|
377
|
+
identifiers, missingness and distribution shift, target-leakage heuristics, and
|
|
378
|
+
target shift are warnings because they can be legitimate properties of a
|
|
379
|
+
dataset. The audit only reports; it never repairs or reorders a split.
|
|
380
|
+
|
|
381
|
+
`groups` may hold labels for both splits (`len(X_train) + len(X_test)`); pass
|
|
382
|
+
`groups_test` when it only covers the training rows. Duplicate checks exclude
|
|
383
|
+
`id_cols` and `time_col`; declared identifiers are still reported under
|
|
384
|
+
`high_cardinality_identifier` when their cardinality is high. Near-duplicates
|
|
385
|
+
are approximated deterministically by hashing rows with numeric features
|
|
386
|
+
rounded to `near_duplicate_decimals` (default `3`).
|
|
387
|
+
|
|
388
|
+
Findings never include raw cell values. Messages carry column names, counts,
|
|
389
|
+
rates, and statistics only, so reports can be logged safely.
|
|
390
|
+
|
|
244
391
|
## Audit trail, manifests, and fingerprints
|
|
245
392
|
|
|
246
393
|
Every learned or configured decision is recorded during `fit()` and exposed as
|
|
@@ -337,7 +484,23 @@ predictions = pipeline.predict(X_test)
|
|
|
337
484
|
| `CleaningDecision` | One auditable learned or configured decision |
|
|
338
485
|
| `ColumnSpec` | Declarative expectations and semantics for one column |
|
|
339
486
|
| `DataContract` | A set of column specs, with inference and (de)serialization |
|
|
487
|
+
| `Contract` | Shorthand alias for `DataContract` |
|
|
488
|
+
| `DataContract.validate()` | Check a batch and return a `ValidationReport` |
|
|
340
489
|
| `DriftReport` | Findings from a contract check, with a Markdown summary |
|
|
490
|
+
| `Expectation` | One reusable expectation produced by a factory |
|
|
491
|
+
| `validate` | Evaluate expectations against a frame |
|
|
492
|
+
| `not_null`, `unique`, `in_set`, `between` | Expectation factories |
|
|
493
|
+
| `matches_pattern`, `has_dtype` | Expectation factories |
|
|
494
|
+
| `row_count_between` | Frame-level row-count expectation |
|
|
495
|
+
| `ValidationReport` | Pass/fail results, failures table, Markdown, and raise helper |
|
|
496
|
+
| `diagnose_join` | Diagnose key duplication, cardinality, and row multiplication |
|
|
497
|
+
| `JoinDiagnosis` | Join report with multiplier, unmatched counts, and warnings |
|
|
498
|
+
| `check_referential_integrity` | Find orphan child keys and non-unique parent keys |
|
|
499
|
+
| `ReferentialIntegrityReport` | Orphan counts/keys, null keys, and validity |
|
|
500
|
+
| `deduplicate_by_business_key` | Deduplicate by key and report removed rows |
|
|
501
|
+
| `DeduplicationReport` | Removed rows, duplicate-key counts, and tie-breaker details |
|
|
502
|
+
| `audit_split` | Audit a train/test split for leakage and distribution shift |
|
|
503
|
+
| `SplitAudit` | Findings table with validity, Markdown, and raise helper |
|
|
341
504
|
| `DataCleaner.drift_report()` | Drift findings from the last `transform` |
|
|
342
505
|
| `DataCleaner.fitted_contract()` | The contract used by the fitted cleaner |
|
|
343
506
|
| `DataCleaner.decision_log()` | Tidy DataFrame of cleaning decisions |
|
|
@@ -381,13 +544,20 @@ predictions = pipeline.predict(X_test)
|
|
|
381
544
|
│ ├── __init__.py # public API re-exports
|
|
382
545
|
│ ├── _version.py # version metadata
|
|
383
546
|
│ ├── _roles.py # semantic roles and dtype helpers
|
|
547
|
+
│ ├── artifacts.py # fingerprints and runtime metadata
|
|
384
548
|
│ ├── contract.py # ColumnSpec / DataContract / DriftReport
|
|
385
549
|
│ ├── config.py # CleanerConfig
|
|
386
550
|
│ ├── cleaner.py # DataCleaner
|
|
551
|
+
│ ├── decisions.py # CleaningDecision and decision log
|
|
552
|
+
│ ├── integration.py # joins, referential integrity, dedup
|
|
553
|
+
│ ├── ml_audit.py # train/test leakage and shift audit
|
|
387
554
|
│ ├── profiling.py # profiling and validation helpers
|
|
555
|
+
│ ├── validation.py # expectations and ValidationReport
|
|
388
556
|
│ └── py.typed # PEP 561 marker
|
|
389
557
|
├── Universal_Data_Cleaner.ipynb # end-to-end reference workflow
|
|
390
|
-
├── tests/test_data_cleaner.py # unit and integration tests
|
|
558
|
+
├── tests/test_data_cleaner.py # core unit and integration tests
|
|
559
|
+
├── tests/test_validation.py # expectations and integration tests
|
|
560
|
+
├── tests/test_ml_audit.py # split/leakage audit tests
|
|
391
561
|
├── pyproject.toml # package metadata and dev tooling
|
|
392
562
|
├── uv.lock # reproducible dependency lock
|
|
393
563
|
├── .pre-commit-config.yaml # local lint/format/type hooks
|
|
@@ -40,6 +40,7 @@ breaks at inference time because the median is recomputed on the new batch.
|
|
|
40
40
|
- automatic train-schema contract inference and transform-time drift reports
|
|
41
41
|
- `on_drift` policy: `raise`, `warn`, or `ignore`
|
|
42
42
|
- identifier columns that are never numeric-coerced, median-imputed, or capped
|
|
43
|
+
- train/test split audits for duplicate, group, temporal, and target leakage
|
|
43
44
|
- joblib save / load with artifact versioning
|
|
44
45
|
- scikit-learn `Pipeline`, `clone`, and `get_feature_names_out` compatibility
|
|
45
46
|
|
|
@@ -208,6 +209,152 @@ restored = DataContract.from_json(payload)
|
|
|
208
209
|
# restored = DataContract.from_yaml(contract.to_yaml())
|
|
209
210
|
```
|
|
210
211
|
|
|
212
|
+
## Expectations, joins, and referential integrity
|
|
213
|
+
|
|
214
|
+
### Expectations and validation reports
|
|
215
|
+
|
|
216
|
+
Run lightweight expectations against any batch and get a shareable report:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
from data_cleaner import (
|
|
220
|
+
between,
|
|
221
|
+
has_dtype,
|
|
222
|
+
in_set,
|
|
223
|
+
matches_pattern,
|
|
224
|
+
not_null,
|
|
225
|
+
row_count_between,
|
|
226
|
+
unique,
|
|
227
|
+
validate,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
report = validate(
|
|
231
|
+
orders_new,
|
|
232
|
+
[
|
|
233
|
+
not_null("order_id"),
|
|
234
|
+
unique("order_id"),
|
|
235
|
+
in_set("status", ["new", "paid", "shipped"]),
|
|
236
|
+
between("amount", 0, 100_000),
|
|
237
|
+
matches_pattern("email", r"[^@]+@[^@]+\.[^@]+"),
|
|
238
|
+
has_dtype("created_at", "datetime"),
|
|
239
|
+
row_count_between(min_rows=1),
|
|
240
|
+
],
|
|
241
|
+
)
|
|
242
|
+
print(report.to_markdown())
|
|
243
|
+
report.raise_if_failed()
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
`report.success` is true when no error-severity expectation failed.
|
|
247
|
+
`report.failures` includes warnings too, so use `severity="warning"` for soft
|
|
248
|
+
checks. `has_dtype` accepts broad kinds (`numeric`, `categorical`, `boolean`,
|
|
249
|
+
`datetime`) or an exact pandas dtype such as `float64`.
|
|
250
|
+
|
|
251
|
+
Contracts can validate a batch directly and return the same report type:
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from data_cleaner import DataContract
|
|
255
|
+
|
|
256
|
+
contract = DataContract.from_frame(orders_train)
|
|
257
|
+
result = contract.validate(orders_new)
|
|
258
|
+
result.failures.to_markdown()
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
`Contract` is a shorthand alias for `DataContract`.
|
|
262
|
+
|
|
263
|
+
### Join diagnostics
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from data_cleaner import diagnose_join
|
|
267
|
+
|
|
268
|
+
report = diagnose_join(orders, customers, on="customer_id", how="left")
|
|
269
|
+
|
|
270
|
+
report.safe # False on cardinality mismatch, left/right row multiplication, or null keys
|
|
271
|
+
report.cardinality # e.g. "1:m"
|
|
272
|
+
report.row_multiplier # output rows / left rows
|
|
273
|
+
report.unmatched_left
|
|
274
|
+
report.unmatched_right
|
|
275
|
+
report.warnings
|
|
276
|
+
report.raise_if_unsafe()
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
`diagnose_join` defaults to `how="left"` and `validate="1:1"`. It reports
|
|
280
|
+
duplicate keys, null keys, unmatched rows, and the actual output row count
|
|
281
|
+
without materializing the full joined frame.
|
|
282
|
+
|
|
283
|
+
### Referential integrity
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
from data_cleaner import check_referential_integrity
|
|
287
|
+
|
|
288
|
+
report = check_referential_integrity(
|
|
289
|
+
orders, customers, child_key="customer_id", parent_key="id"
|
|
290
|
+
)
|
|
291
|
+
report.orphan_rows
|
|
292
|
+
report.orphan_keys
|
|
293
|
+
report.raise_if_invalid()
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Null child keys are reported but allowed by default (`allow_null_keys=True`).
|
|
297
|
+
Duplicate parent keys make the relationship invalid because the parent key is
|
|
298
|
+
not a unique reference target.
|
|
299
|
+
|
|
300
|
+
### Business-key deduplication
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
from data_cleaner import deduplicate_by_business_key
|
|
304
|
+
|
|
305
|
+
deduped, report = deduplicate_by_business_key(
|
|
306
|
+
orders, key="order_id", keep="last", tie_breaker="updated_at"
|
|
307
|
+
)
|
|
308
|
+
report.removed_rows
|
|
309
|
+
report.removed # the actual rows that were dropped
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
The returned frame preserves the input row order and index. `tie_breaker`
|
|
313
|
+
prefers non-null values, and null business keys are reported explicitly.
|
|
314
|
+
The input frame is never mutated.
|
|
315
|
+
|
|
316
|
+
## ML split audits
|
|
317
|
+
|
|
318
|
+
Audit a train/test split for contamination and distribution surprises before
|
|
319
|
+
training:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
from data_cleaner import audit_split
|
|
323
|
+
|
|
324
|
+
audit = audit_split(
|
|
325
|
+
X_train,
|
|
326
|
+
X_test,
|
|
327
|
+
y_train,
|
|
328
|
+
y_test,
|
|
329
|
+
groups=groups, # combined train+test labels, or pass groups_test=
|
|
330
|
+
time_col="event_time",
|
|
331
|
+
id_cols=["customer_id"],
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
audit.valid # False when an error-severity finding exists
|
|
335
|
+
audit.findings # check, column, severity, message, train, test
|
|
336
|
+
audit.summary()
|
|
337
|
+
audit.to_markdown()
|
|
338
|
+
audit.raise_if_invalid()
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Schema problems such as missing columns, empty splits, exact duplicate overlap,
|
|
342
|
+
group leakage, temporal leakage, and unparseable or numeric timestamps are
|
|
343
|
+
errors. Near-duplicates, constant / near-constant columns, high-cardinality
|
|
344
|
+
identifiers, missingness and distribution shift, target-leakage heuristics, and
|
|
345
|
+
target shift are warnings because they can be legitimate properties of a
|
|
346
|
+
dataset. The audit only reports; it never repairs or reorders a split.
|
|
347
|
+
|
|
348
|
+
`groups` may hold labels for both splits (`len(X_train) + len(X_test)`); pass
|
|
349
|
+
`groups_test` when it only covers the training rows. Duplicate checks exclude
|
|
350
|
+
`id_cols` and `time_col`; declared identifiers are still reported under
|
|
351
|
+
`high_cardinality_identifier` when their cardinality is high. Near-duplicates
|
|
352
|
+
are approximated deterministically by hashing rows with numeric features
|
|
353
|
+
rounded to `near_duplicate_decimals` (default `3`).
|
|
354
|
+
|
|
355
|
+
Findings never include raw cell values. Messages carry column names, counts,
|
|
356
|
+
rates, and statistics only, so reports can be logged safely.
|
|
357
|
+
|
|
211
358
|
## Audit trail, manifests, and fingerprints
|
|
212
359
|
|
|
213
360
|
Every learned or configured decision is recorded during `fit()` and exposed as
|
|
@@ -304,7 +451,23 @@ predictions = pipeline.predict(X_test)
|
|
|
304
451
|
| `CleaningDecision` | One auditable learned or configured decision |
|
|
305
452
|
| `ColumnSpec` | Declarative expectations and semantics for one column |
|
|
306
453
|
| `DataContract` | A set of column specs, with inference and (de)serialization |
|
|
454
|
+
| `Contract` | Shorthand alias for `DataContract` |
|
|
455
|
+
| `DataContract.validate()` | Check a batch and return a `ValidationReport` |
|
|
307
456
|
| `DriftReport` | Findings from a contract check, with a Markdown summary |
|
|
457
|
+
| `Expectation` | One reusable expectation produced by a factory |
|
|
458
|
+
| `validate` | Evaluate expectations against a frame |
|
|
459
|
+
| `not_null`, `unique`, `in_set`, `between` | Expectation factories |
|
|
460
|
+
| `matches_pattern`, `has_dtype` | Expectation factories |
|
|
461
|
+
| `row_count_between` | Frame-level row-count expectation |
|
|
462
|
+
| `ValidationReport` | Pass/fail results, failures table, Markdown, and raise helper |
|
|
463
|
+
| `diagnose_join` | Diagnose key duplication, cardinality, and row multiplication |
|
|
464
|
+
| `JoinDiagnosis` | Join report with multiplier, unmatched counts, and warnings |
|
|
465
|
+
| `check_referential_integrity` | Find orphan child keys and non-unique parent keys |
|
|
466
|
+
| `ReferentialIntegrityReport` | Orphan counts/keys, null keys, and validity |
|
|
467
|
+
| `deduplicate_by_business_key` | Deduplicate by key and report removed rows |
|
|
468
|
+
| `DeduplicationReport` | Removed rows, duplicate-key counts, and tie-breaker details |
|
|
469
|
+
| `audit_split` | Audit a train/test split for leakage and distribution shift |
|
|
470
|
+
| `SplitAudit` | Findings table with validity, Markdown, and raise helper |
|
|
308
471
|
| `DataCleaner.drift_report()` | Drift findings from the last `transform` |
|
|
309
472
|
| `DataCleaner.fitted_contract()` | The contract used by the fitted cleaner |
|
|
310
473
|
| `DataCleaner.decision_log()` | Tidy DataFrame of cleaning decisions |
|
|
@@ -348,13 +511,20 @@ predictions = pipeline.predict(X_test)
|
|
|
348
511
|
│ ├── __init__.py # public API re-exports
|
|
349
512
|
│ ├── _version.py # version metadata
|
|
350
513
|
│ ├── _roles.py # semantic roles and dtype helpers
|
|
514
|
+
│ ├── artifacts.py # fingerprints and runtime metadata
|
|
351
515
|
│ ├── contract.py # ColumnSpec / DataContract / DriftReport
|
|
352
516
|
│ ├── config.py # CleanerConfig
|
|
353
517
|
│ ├── cleaner.py # DataCleaner
|
|
518
|
+
│ ├── decisions.py # CleaningDecision and decision log
|
|
519
|
+
│ ├── integration.py # joins, referential integrity, dedup
|
|
520
|
+
│ ├── ml_audit.py # train/test leakage and shift audit
|
|
354
521
|
│ ├── profiling.py # profiling and validation helpers
|
|
522
|
+
│ ├── validation.py # expectations and ValidationReport
|
|
355
523
|
│ └── py.typed # PEP 561 marker
|
|
356
524
|
├── Universal_Data_Cleaner.ipynb # end-to-end reference workflow
|
|
357
|
-
├── tests/test_data_cleaner.py # unit and integration tests
|
|
525
|
+
├── tests/test_data_cleaner.py # core unit and integration tests
|
|
526
|
+
├── tests/test_validation.py # expectations and integration tests
|
|
527
|
+
├── tests/test_ml_audit.py # split/leakage audit tests
|
|
358
528
|
├── pyproject.toml # package metadata and dev tooling
|
|
359
529
|
├── uv.lock # reproducible dependency lock
|
|
360
530
|
├── .pre-commit-config.yaml # local lint/format/type hooks
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "universal-data-cleaner"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.5.0"
|
|
8
8
|
description = "Production-ready, scikit-learn-compatible data cleaning transformer for pandas."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -20,28 +20,70 @@ from .artifacts import (
|
|
|
20
20
|
)
|
|
21
21
|
from .cleaner import DataCleaner
|
|
22
22
|
from .config import CleanerConfig
|
|
23
|
-
from .contract import ColumnSpec, DataContract, DriftReport
|
|
23
|
+
from .contract import ColumnSpec, Contract, DataContract, DriftReport
|
|
24
24
|
from .decisions import CleaningDecision
|
|
25
|
+
from .integration import (
|
|
26
|
+
DeduplicationReport,
|
|
27
|
+
JoinDiagnosis,
|
|
28
|
+
ReferentialIntegrityReport,
|
|
29
|
+
check_referential_integrity,
|
|
30
|
+
deduplicate_by_business_key,
|
|
31
|
+
diagnose_join,
|
|
32
|
+
)
|
|
33
|
+
from .ml_audit import SplitAudit, audit_split
|
|
25
34
|
from .profiling import (
|
|
26
35
|
assert_frame_clean,
|
|
27
36
|
dataset_summary,
|
|
28
37
|
drop_duplicate_rows,
|
|
29
38
|
profile_dataframe,
|
|
30
39
|
)
|
|
40
|
+
from .validation import (
|
|
41
|
+
Expectation,
|
|
42
|
+
ValidationReport,
|
|
43
|
+
ValidationResult,
|
|
44
|
+
between,
|
|
45
|
+
has_dtype,
|
|
46
|
+
in_set,
|
|
47
|
+
matches_pattern,
|
|
48
|
+
not_null,
|
|
49
|
+
row_count_between,
|
|
50
|
+
unique,
|
|
51
|
+
validate,
|
|
52
|
+
)
|
|
31
53
|
|
|
32
54
|
__all__ = [
|
|
33
55
|
"CleanerConfig",
|
|
34
56
|
"CleaningDecision",
|
|
35
57
|
"ColumnSpec",
|
|
58
|
+
"Contract",
|
|
36
59
|
"DataCleaner",
|
|
37
60
|
"DataContract",
|
|
61
|
+
"DeduplicationReport",
|
|
38
62
|
"DriftReport",
|
|
63
|
+
"Expectation",
|
|
64
|
+
"JoinDiagnosis",
|
|
65
|
+
"ReferentialIntegrityReport",
|
|
66
|
+
"SplitAudit",
|
|
67
|
+
"ValidationReport",
|
|
68
|
+
"ValidationResult",
|
|
39
69
|
"__version__",
|
|
40
70
|
"assert_frame_clean",
|
|
41
71
|
"assert_schema_stable",
|
|
72
|
+
"audit_split",
|
|
73
|
+
"between",
|
|
74
|
+
"check_referential_integrity",
|
|
42
75
|
"compare_fingerprints",
|
|
43
76
|
"dataset_summary",
|
|
77
|
+
"deduplicate_by_business_key",
|
|
78
|
+
"diagnose_join",
|
|
44
79
|
"drop_duplicate_rows",
|
|
45
80
|
"fingerprint_dataframe",
|
|
81
|
+
"has_dtype",
|
|
82
|
+
"in_set",
|
|
83
|
+
"matches_pattern",
|
|
84
|
+
"not_null",
|
|
46
85
|
"profile_dataframe",
|
|
86
|
+
"row_count_between",
|
|
87
|
+
"unique",
|
|
88
|
+
"validate",
|
|
47
89
|
]
|
|
@@ -16,6 +16,7 @@ from ._roles import (
|
|
|
16
16
|
_normalize_role,
|
|
17
17
|
_series_kind,
|
|
18
18
|
)
|
|
19
|
+
from .validation import ValidationReport
|
|
19
20
|
|
|
20
21
|
if TYPE_CHECKING:
|
|
21
22
|
from .config import CleanerConfig
|
|
@@ -217,6 +218,20 @@ class DataContract:
|
|
|
217
218
|
)
|
|
218
219
|
return cls(columns=tuple(specs), strict=strict)
|
|
219
220
|
|
|
221
|
+
@classmethod
|
|
222
|
+
def from_frame(
|
|
223
|
+
cls,
|
|
224
|
+
frame: pd.DataFrame,
|
|
225
|
+
config: CleanerConfig | None = None,
|
|
226
|
+
strict: bool = True,
|
|
227
|
+
) -> DataContract:
|
|
228
|
+
"""Infer a contract from ``frame`` (alias for :meth:`infer_from`)."""
|
|
229
|
+
return cls.infer_from(frame, config=config, strict=strict)
|
|
230
|
+
|
|
231
|
+
def validate(self, frame: pd.DataFrame) -> ValidationReport:
|
|
232
|
+
"""Check ``frame`` against this contract and return a validation report."""
|
|
233
|
+
return ValidationReport.from_findings(self.check(frame).findings)
|
|
234
|
+
|
|
220
235
|
@staticmethod
|
|
221
236
|
def _finding(
|
|
222
237
|
spec: ColumnSpec,
|
|
@@ -427,3 +442,7 @@ class DataContract:
|
|
|
427
442
|
"`pip install pyyaml` or use to_json()/from_json()."
|
|
428
443
|
) from exc
|
|
429
444
|
return cls.from_dict(yaml.safe_load(text))
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
#: Shorthand alias for :class:`DataContract`.
|
|
448
|
+
Contract = DataContract
|