sanitizepy 0.1.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.
- sanitizepy-0.1.0/LICENSE +21 -0
- sanitizepy-0.1.0/PKG-INFO +261 -0
- sanitizepy-0.1.0/README.md +227 -0
- sanitizepy-0.1.0/pyproject.toml +107 -0
- sanitizepy-0.1.0/setup.cfg +4 -0
- sanitizepy-0.1.0/src/sanitizepy/__init__.py +54 -0
- sanitizepy-0.1.0/src/sanitizepy/api.py +33 -0
- sanitizepy-0.1.0/src/sanitizepy/cleaning/__init__.py +24 -0
- sanitizepy-0.1.0/src/sanitizepy/cleaning/base.py +132 -0
- sanitizepy-0.1.0/src/sanitizepy/cleaning/engine.py +163 -0
- sanitizepy-0.1.0/src/sanitizepy/cleaning/operations.py +180 -0
- sanitizepy-0.1.0/src/sanitizepy/cleaning/plan.py +157 -0
- sanitizepy-0.1.0/src/sanitizepy/config.py +94 -0
- sanitizepy-0.1.0/src/sanitizepy/constants.py +161 -0
- sanitizepy-0.1.0/src/sanitizepy/core.py +105 -0
- sanitizepy-0.1.0/src/sanitizepy/engine/__init__.py +15 -0
- sanitizepy-0.1.0/src/sanitizepy/engine/base.py +59 -0
- sanitizepy-0.1.0/src/sanitizepy/exceptions.py +348 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/__init__.py +73 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/datatypes.py +219 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/detector.py +425 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/duplicates.py +176 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/health.py +134 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/memory.py +271 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/missing.py +206 -0
- sanitizepy-0.1.0/src/sanitizepy/inspection/statistics.py +225 -0
- sanitizepy-0.1.0/src/sanitizepy/logger.py +82 -0
- sanitizepy-0.1.0/src/sanitizepy/models/__init__.py +94 -0
- sanitizepy-0.1.0/src/sanitizepy/models/base.py +201 -0
- sanitizepy-0.1.0/src/sanitizepy/models/inspection.py +242 -0
- sanitizepy-0.1.0/src/sanitizepy/models/recommendations.py +221 -0
- sanitizepy-0.1.0/src/sanitizepy/models/report.py +105 -0
- sanitizepy-0.1.0/src/sanitizepy/pipeline/__init__.py +18 -0
- sanitizepy-0.1.0/src/sanitizepy/pipeline/base.py +50 -0
- sanitizepy-0.1.0/src/sanitizepy/pipeline/engine.py +171 -0
- sanitizepy-0.1.0/src/sanitizepy/pipeline/steps.py +83 -0
- sanitizepy-0.1.0/src/sanitizepy/preprocessing/__init__.py +19 -0
- sanitizepy-0.1.0/src/sanitizepy/preprocessing/base.py +140 -0
- sanitizepy-0.1.0/src/sanitizepy/preprocessing/engine.py +190 -0
- sanitizepy-0.1.0/src/sanitizepy/preprocessing/operations.py +535 -0
- sanitizepy-0.1.0/src/sanitizepy/reports/__init__.py +25 -0
- sanitizepy-0.1.0/src/sanitizepy/reports/base.py +53 -0
- sanitizepy-0.1.0/src/sanitizepy/reports/engine.py +103 -0
- sanitizepy-0.1.0/src/sanitizepy/reports/exporters.py +99 -0
- sanitizepy-0.1.0/src/sanitizepy/reports/renderers.py +106 -0
- sanitizepy-0.1.0/src/sanitizepy/reports/report.py +102 -0
- sanitizepy-0.1.0/src/sanitizepy/rules/__init__.py +23 -0
- sanitizepy-0.1.0/src/sanitizepy/rules/base.py +93 -0
- sanitizepy-0.1.0/src/sanitizepy/rules/builtins.py +99 -0
- sanitizepy-0.1.0/src/sanitizepy/rules/engine.py +58 -0
- sanitizepy-0.1.0/src/sanitizepy/rules/registry.py +91 -0
- sanitizepy-0.1.0/src/sanitizepy/rules/rule.py +97 -0
- sanitizepy-0.1.0/src/sanitizepy/rules/validators.py +94 -0
- sanitizepy-0.1.0/src/sanitizepy/types.py +0 -0
- sanitizepy-0.1.0/src/sanitizepy/utils/__init__.py +0 -0
- sanitizepy-0.1.0/src/sanitizepy/version.py +49 -0
- sanitizepy-0.1.0/src/sanitizepy.egg-info/PKG-INFO +261 -0
- sanitizepy-0.1.0/src/sanitizepy.egg-info/SOURCES.txt +77 -0
- sanitizepy-0.1.0/src/sanitizepy.egg-info/dependency_links.txt +1 -0
- sanitizepy-0.1.0/src/sanitizepy.egg-info/requires.txt +13 -0
- sanitizepy-0.1.0/src/sanitizepy.egg-info/top_level.txt +1 -0
- sanitizepy-0.1.0/tests/test_cleaning_base.py +42 -0
- sanitizepy-0.1.0/tests/test_cleaning_operations.py +223 -0
- sanitizepy-0.1.0/tests/test_config.py +119 -0
- sanitizepy-0.1.0/tests/test_constants.py +137 -0
- sanitizepy-0.1.0/tests/test_core.py +80 -0
- sanitizepy-0.1.0/tests/test_edge_cases.py +245 -0
- sanitizepy-0.1.0/tests/test_exceptions.py +192 -0
- sanitizepy-0.1.0/tests/test_high_level_api.py +127 -0
- sanitizepy-0.1.0/tests/test_inspection_datatypes.py +178 -0
- sanitizepy-0.1.0/tests/test_inspection_duplicates.py +181 -0
- sanitizepy-0.1.0/tests/test_inspection_memory.py +155 -0
- sanitizepy-0.1.0/tests/test_inspection_missing.py +175 -0
- sanitizepy-0.1.0/tests/test_inspection_statistics.py +187 -0
- sanitizepy-0.1.0/tests/test_logger.py +52 -0
- sanitizepy-0.1.0/tests/test_preprocessing_base.py +75 -0
- sanitizepy-0.1.0/tests/test_preprocessing_operations.py +378 -0
- sanitizepy-0.1.0/tests/test_rules.py +341 -0
- sanitizepy-0.1.0/tests/test_version.py +46 -0
sanitizepy-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Syed Muhammad Taha Hassan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sanitizepy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An open-source Python engine for automated tabular data quality inspection, explainable cleaning, and preprocessing.
|
|
5
|
+
Author: Syed Muhammad Taha Hassan
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: machine-learning,data-quality,data-cleaning,eda,feature-engineering,preprocessing,pandas,python,data-analysis
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: numpy<2.3.0,>=1.24.0
|
|
22
|
+
Requires-Dist: pandas>=2.0.0
|
|
23
|
+
Requires-Dist: scipy>=1.10.0
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Requires-Dist: pydantic>=2.0.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: black>=24.0.0; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
29
|
+
Requires-Dist: mypy>=1.10.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pandas-stubs>=2.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# sanitizepy
|
|
37
|
+
|
|
38
|
+
An open-source Python engine for automated tabular data quality inspection, explainable cleaning, and preprocessing.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Overview
|
|
43
|
+
|
|
44
|
+
`sanitizepy` provides modular, high-performance data engineering components built on top of `pandas`, `numpy`, `scipy`, `rich`, and `pydantic`. The library is designed around a transparent **Detect → Explain → Recommend → Preview → Apply → Validate → Audit** workflow.
|
|
45
|
+
|
|
46
|
+
`sanitizepy` separates responsibilities into dedicated subsystems:
|
|
47
|
+
- **Core Engine & High-Level API**: Centralized `Cleaner` entry point supporting `.inspect()`, `.plan()`, and `.clean(..., dry_run=True)`.
|
|
48
|
+
- **Dataset Health & Inspection**: Read-only dataset analysis covering completeness, uniqueness, consistency, validity, datatypes, memory consumption, and statistical distributions with a composite **Dataset Health Score (0–100)**.
|
|
49
|
+
- **Explainable Recommendations & Planning**: Rule-based issue detection with human-readable explanations (`WHAT`, `WHY`, `SEVERITY`, `EVIDENCE`, `RECOMMENDATION`) and previewable `CleaningPlan` instances.
|
|
50
|
+
- **Cleaning Engine**: Safe, deterministic dataset transformations with dry-run support, before/after impact metrics, and detailed audit trails.
|
|
51
|
+
- **Preprocessing & Feature Engineering**: Stateful fit/transform operations for interactions, ratio features, polynomial terms, logarithmic transformations, and datetime extraction.
|
|
52
|
+
- **Rule Engine**: Quality validation framework with built-in rules, severity levels, and category classifications.
|
|
53
|
+
- **Report Engine**: Structured report generation, rendering (Text, JSON), and exporting (String, File).
|
|
54
|
+
- **Pipeline Engine**: Execution workflow orchestration with step timing and metadata tracking.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Capabilities
|
|
59
|
+
|
|
60
|
+
| Area | Component | Key Functionality |
|
|
61
|
+
| :--- | :--- | :--- |
|
|
62
|
+
| **Core & High-Level API** | `Cleaner`, `CleanerConfig` | Unified entry point for `.inspect()`, `.plan()`, and `.clean(..., dry_run=True)` |
|
|
63
|
+
| **Dataset Health & Inspection** | `Cleaner.inspect()`, `MissingValueInspector`, `DuplicateInspector`, `DatatypeInspector`, `MemoryInspector`, `StatisticsInspector` | Dataset Health Score (0-100), severity scoring, memory estimation, distribution stats |
|
|
64
|
+
| **Recommendations & Planning** | `CleaningPlan`, `IssueDetector` | Human-readable recommendations, issue severity classification (`critical`, `warning`, `info`), previewable execution plan |
|
|
65
|
+
| **Cleaning Engine** | `CleaningEngine`, `DropMissingRows`, `DropMissingColumns`, `FillMissing`, `DropDuplicates`, `DropColumns` | Deterministic cleaning operations with `dry_run` support, `OperationResult`, and immutable audit log |
|
|
66
|
+
| **Preprocessing** | `FeatureEngineeringEngine`, `ColumnInteraction`, `RatioFeature`, `PolynomialFeature`, `LogFeature`, `DatetimeFeatures` | Stateful fit/transform feature generation preserving dataset indices |
|
|
67
|
+
| **Rules** | `RuleEngine`, `RuleRegistry`, `Rule`, `register_builtin_rules` | Data quality rules, severity levels (`info`, `warning`, `error`, `critical`), custom rules |
|
|
68
|
+
| **Reporting** | `ReportEngine`, `TextRenderer`, `JSONRenderer`, `StringExporter`, `FileExporter` | Structured immutable reports with multi-format rendering and exporting |
|
|
69
|
+
| **Pipeline** | `PipelineEngine`, `CallableStep`, `TransformStep` | Sequenced workflow execution with step duration and row/column metrics |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Requirements
|
|
74
|
+
|
|
75
|
+
- **Python**: `>=3.11`
|
|
76
|
+
- **Core Dependencies**:
|
|
77
|
+
- `numpy >= 1.24.0`
|
|
78
|
+
- `pandas >= 2.0.0`
|
|
79
|
+
- `scipy >= 1.10.0`
|
|
80
|
+
- `rich >= 13.0.0`
|
|
81
|
+
- `pydantic >= 2.0.0`
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
### Standard User Installation
|
|
88
|
+
|
|
89
|
+
Install `sanitizepy` using `pip`:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install sanitizepy
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Or via `python -m pip`:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
python -m pip install sanitizepy
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Developer / Contributor Installation
|
|
102
|
+
|
|
103
|
+
For local development or contributing to the codebase, clone the repository and perform an editable installation with development dependencies:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
git clone https://github.com/tahahssn/sanitizepy.git
|
|
107
|
+
cd sanitizepy
|
|
108
|
+
pip install -e .[dev]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Quick Start — High-Level API
|
|
114
|
+
|
|
115
|
+
The recommended entry point is the `Cleaner` class or the module-level convenience functions `inspect()`, `plan()`, and `clean()`.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import pandas as pd
|
|
119
|
+
from sanitizepy import Cleaner
|
|
120
|
+
|
|
121
|
+
# Load your dataset
|
|
122
|
+
df = pd.read_csv("your_data.csv")
|
|
123
|
+
|
|
124
|
+
# 1. Inspect — Understand what's wrong
|
|
125
|
+
c = Cleaner()
|
|
126
|
+
report = c.inspect(df)
|
|
127
|
+
report.show() # Rich terminal health report
|
|
128
|
+
|
|
129
|
+
print(f"Health Score: {report.health_score}/100")
|
|
130
|
+
print(f"Critical Issues: {len(report.critical_issues)}")
|
|
131
|
+
print(f"Recommendations: {len(report.recommendations)}")
|
|
132
|
+
|
|
133
|
+
# 2. Plan — Generate a previewable cleaning plan
|
|
134
|
+
plan = c.plan(report)
|
|
135
|
+
plan.show() # Tabular plan preview
|
|
136
|
+
|
|
137
|
+
# Optional: disable or enable specific steps
|
|
138
|
+
plan.disable(2) # Disable step #2
|
|
139
|
+
plan.enable(2) # Re-enable step #2
|
|
140
|
+
|
|
141
|
+
# 3. Clean — Execute with dry-run or for real
|
|
142
|
+
# Dry run: see what WOULD happen without changing data
|
|
143
|
+
dry_result = c.clean(df, plan=plan, dry_run=True)
|
|
144
|
+
print(dry_result.summary())
|
|
145
|
+
|
|
146
|
+
# Apply for real
|
|
147
|
+
result = c.clean(df, plan=plan, dry_run=False)
|
|
148
|
+
cleaned_df = result.data
|
|
149
|
+
|
|
150
|
+
print(result.summary()) # Human-readable summary
|
|
151
|
+
print(result.audit_log) # JSON-serializable audit trail
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Convenience Functions
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from sanitizepy import inspect, plan, clean
|
|
158
|
+
|
|
159
|
+
report = inspect(df)
|
|
160
|
+
cleaning_plan = plan(report)
|
|
161
|
+
result = clean(df, cleaning_plan=cleaning_plan, dry_run=True)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Advanced Usage — Direct Engine Access
|
|
167
|
+
|
|
168
|
+
For granular control, use the individual engines directly:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from sanitizepy.cleaning import CleaningEngine, DropDuplicates, FillMissing
|
|
172
|
+
from sanitizepy.inspection import MissingValueInspector
|
|
173
|
+
|
|
174
|
+
# Read-only inspection
|
|
175
|
+
inspector = MissingValueInspector()
|
|
176
|
+
inspection_result = inspector.inspect(df)
|
|
177
|
+
|
|
178
|
+
# Manual cleaning engine
|
|
179
|
+
engine = CleaningEngine([
|
|
180
|
+
FillMissing(value=0.0, subset=["numeric_column"]),
|
|
181
|
+
DropDuplicates(keep="first"),
|
|
182
|
+
])
|
|
183
|
+
|
|
184
|
+
# Run with full result tracking
|
|
185
|
+
result = engine.run_with_result(df, dry_run=False)
|
|
186
|
+
print(result.summary())
|
|
187
|
+
print(result.audit_log)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Architecture & Design
|
|
193
|
+
|
|
194
|
+
`sanitizepy` adopts the following transparent workflow:
|
|
195
|
+
**Detect → Explain → Recommend → Preview → Apply → Validate → Audit**
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
┌───────────────────────┐
|
|
199
|
+
│ Dataset │
|
|
200
|
+
└───────────┬───────────┘
|
|
201
|
+
│
|
|
202
|
+
┌─────────────┴─────────────┐
|
|
203
|
+
│ Dataset Profiler / │
|
|
204
|
+
│ Issue Detector │ (Read-Only)
|
|
205
|
+
└─────────────┬─────────────┘
|
|
206
|
+
│
|
|
207
|
+
┌─────────────┴─────────────┐
|
|
208
|
+
│ Recommendation Engine │ (Explainable)
|
|
209
|
+
└─────────────┬─────────────┘
|
|
210
|
+
│
|
|
211
|
+
┌─────────────┴─────────────┐
|
|
212
|
+
│ Cleaning Plan │ (Previewable)
|
|
213
|
+
└─────────────┬─────────────┘
|
|
214
|
+
│
|
|
215
|
+
user approves
|
|
216
|
+
│
|
|
217
|
+
┌─────────────┴─────────────┐
|
|
218
|
+
│ Transformation Engine │ (Deterministic)
|
|
219
|
+
└─────────────┬─────────────┘
|
|
220
|
+
│
|
|
221
|
+
┌─────────────┴─────────────┐
|
|
222
|
+
│ Validation / Audit │ (Auditable)
|
|
223
|
+
└───────────────────────────┘
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Documentation
|
|
229
|
+
|
|
230
|
+
Detailed documentation is available in the `docs/` directory:
|
|
231
|
+
|
|
232
|
+
- [Installation Guide](docs/installation.md): Requirements, virtual environments, installation commands, verification, and upgrade procedures.
|
|
233
|
+
- [Quick Start Guide](docs/quickstart.md): Step-by-step examples for inspection, cleaning, feature engineering, rules, reporting, and pipelines.
|
|
234
|
+
- [API Reference](docs/api.md): Complete technical API documentation for classes, functions, dataclasses, models, and exceptions.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Development & Testing
|
|
239
|
+
|
|
240
|
+
To run the project test suite or linting tools:
|
|
241
|
+
|
|
242
|
+
### Run Tests
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
pytest
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Code Formatting & Linting
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
black --check src tests
|
|
252
|
+
ruff check src tests
|
|
253
|
+
mypy src
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
`sanitizepy` is distributed under the terms of the [MIT License](LICENSE).
|
|
261
|
+
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
|
|
2
|
+
# sanitizepy
|
|
3
|
+
|
|
4
|
+
An open-source Python engine for automated tabular data quality inspection, explainable cleaning, and preprocessing.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`sanitizepy` provides modular, high-performance data engineering components built on top of `pandas`, `numpy`, `scipy`, `rich`, and `pydantic`. The library is designed around a transparent **Detect → Explain → Recommend → Preview → Apply → Validate → Audit** workflow.
|
|
11
|
+
|
|
12
|
+
`sanitizepy` separates responsibilities into dedicated subsystems:
|
|
13
|
+
- **Core Engine & High-Level API**: Centralized `Cleaner` entry point supporting `.inspect()`, `.plan()`, and `.clean(..., dry_run=True)`.
|
|
14
|
+
- **Dataset Health & Inspection**: Read-only dataset analysis covering completeness, uniqueness, consistency, validity, datatypes, memory consumption, and statistical distributions with a composite **Dataset Health Score (0–100)**.
|
|
15
|
+
- **Explainable Recommendations & Planning**: Rule-based issue detection with human-readable explanations (`WHAT`, `WHY`, `SEVERITY`, `EVIDENCE`, `RECOMMENDATION`) and previewable `CleaningPlan` instances.
|
|
16
|
+
- **Cleaning Engine**: Safe, deterministic dataset transformations with dry-run support, before/after impact metrics, and detailed audit trails.
|
|
17
|
+
- **Preprocessing & Feature Engineering**: Stateful fit/transform operations for interactions, ratio features, polynomial terms, logarithmic transformations, and datetime extraction.
|
|
18
|
+
- **Rule Engine**: Quality validation framework with built-in rules, severity levels, and category classifications.
|
|
19
|
+
- **Report Engine**: Structured report generation, rendering (Text, JSON), and exporting (String, File).
|
|
20
|
+
- **Pipeline Engine**: Execution workflow orchestration with step timing and metadata tracking.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Capabilities
|
|
25
|
+
|
|
26
|
+
| Area | Component | Key Functionality |
|
|
27
|
+
| :--- | :--- | :--- |
|
|
28
|
+
| **Core & High-Level API** | `Cleaner`, `CleanerConfig` | Unified entry point for `.inspect()`, `.plan()`, and `.clean(..., dry_run=True)` |
|
|
29
|
+
| **Dataset Health & Inspection** | `Cleaner.inspect()`, `MissingValueInspector`, `DuplicateInspector`, `DatatypeInspector`, `MemoryInspector`, `StatisticsInspector` | Dataset Health Score (0-100), severity scoring, memory estimation, distribution stats |
|
|
30
|
+
| **Recommendations & Planning** | `CleaningPlan`, `IssueDetector` | Human-readable recommendations, issue severity classification (`critical`, `warning`, `info`), previewable execution plan |
|
|
31
|
+
| **Cleaning Engine** | `CleaningEngine`, `DropMissingRows`, `DropMissingColumns`, `FillMissing`, `DropDuplicates`, `DropColumns` | Deterministic cleaning operations with `dry_run` support, `OperationResult`, and immutable audit log |
|
|
32
|
+
| **Preprocessing** | `FeatureEngineeringEngine`, `ColumnInteraction`, `RatioFeature`, `PolynomialFeature`, `LogFeature`, `DatetimeFeatures` | Stateful fit/transform feature generation preserving dataset indices |
|
|
33
|
+
| **Rules** | `RuleEngine`, `RuleRegistry`, `Rule`, `register_builtin_rules` | Data quality rules, severity levels (`info`, `warning`, `error`, `critical`), custom rules |
|
|
34
|
+
| **Reporting** | `ReportEngine`, `TextRenderer`, `JSONRenderer`, `StringExporter`, `FileExporter` | Structured immutable reports with multi-format rendering and exporting |
|
|
35
|
+
| **Pipeline** | `PipelineEngine`, `CallableStep`, `TransformStep` | Sequenced workflow execution with step duration and row/column metrics |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Requirements
|
|
40
|
+
|
|
41
|
+
- **Python**: `>=3.11`
|
|
42
|
+
- **Core Dependencies**:
|
|
43
|
+
- `numpy >= 1.24.0`
|
|
44
|
+
- `pandas >= 2.0.0`
|
|
45
|
+
- `scipy >= 1.10.0`
|
|
46
|
+
- `rich >= 13.0.0`
|
|
47
|
+
- `pydantic >= 2.0.0`
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
### Standard User Installation
|
|
54
|
+
|
|
55
|
+
Install `sanitizepy` using `pip`:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install sanitizepy
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or via `python -m pip`:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
python -m pip install sanitizepy
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Developer / Contributor Installation
|
|
68
|
+
|
|
69
|
+
For local development or contributing to the codebase, clone the repository and perform an editable installation with development dependencies:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/tahahssn/sanitizepy.git
|
|
73
|
+
cd sanitizepy
|
|
74
|
+
pip install -e .[dev]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Quick Start — High-Level API
|
|
80
|
+
|
|
81
|
+
The recommended entry point is the `Cleaner` class or the module-level convenience functions `inspect()`, `plan()`, and `clean()`.
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import pandas as pd
|
|
85
|
+
from sanitizepy import Cleaner
|
|
86
|
+
|
|
87
|
+
# Load your dataset
|
|
88
|
+
df = pd.read_csv("your_data.csv")
|
|
89
|
+
|
|
90
|
+
# 1. Inspect — Understand what's wrong
|
|
91
|
+
c = Cleaner()
|
|
92
|
+
report = c.inspect(df)
|
|
93
|
+
report.show() # Rich terminal health report
|
|
94
|
+
|
|
95
|
+
print(f"Health Score: {report.health_score}/100")
|
|
96
|
+
print(f"Critical Issues: {len(report.critical_issues)}")
|
|
97
|
+
print(f"Recommendations: {len(report.recommendations)}")
|
|
98
|
+
|
|
99
|
+
# 2. Plan — Generate a previewable cleaning plan
|
|
100
|
+
plan = c.plan(report)
|
|
101
|
+
plan.show() # Tabular plan preview
|
|
102
|
+
|
|
103
|
+
# Optional: disable or enable specific steps
|
|
104
|
+
plan.disable(2) # Disable step #2
|
|
105
|
+
plan.enable(2) # Re-enable step #2
|
|
106
|
+
|
|
107
|
+
# 3. Clean — Execute with dry-run or for real
|
|
108
|
+
# Dry run: see what WOULD happen without changing data
|
|
109
|
+
dry_result = c.clean(df, plan=plan, dry_run=True)
|
|
110
|
+
print(dry_result.summary())
|
|
111
|
+
|
|
112
|
+
# Apply for real
|
|
113
|
+
result = c.clean(df, plan=plan, dry_run=False)
|
|
114
|
+
cleaned_df = result.data
|
|
115
|
+
|
|
116
|
+
print(result.summary()) # Human-readable summary
|
|
117
|
+
print(result.audit_log) # JSON-serializable audit trail
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Convenience Functions
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from sanitizepy import inspect, plan, clean
|
|
124
|
+
|
|
125
|
+
report = inspect(df)
|
|
126
|
+
cleaning_plan = plan(report)
|
|
127
|
+
result = clean(df, cleaning_plan=cleaning_plan, dry_run=True)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Advanced Usage — Direct Engine Access
|
|
133
|
+
|
|
134
|
+
For granular control, use the individual engines directly:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from sanitizepy.cleaning import CleaningEngine, DropDuplicates, FillMissing
|
|
138
|
+
from sanitizepy.inspection import MissingValueInspector
|
|
139
|
+
|
|
140
|
+
# Read-only inspection
|
|
141
|
+
inspector = MissingValueInspector()
|
|
142
|
+
inspection_result = inspector.inspect(df)
|
|
143
|
+
|
|
144
|
+
# Manual cleaning engine
|
|
145
|
+
engine = CleaningEngine([
|
|
146
|
+
FillMissing(value=0.0, subset=["numeric_column"]),
|
|
147
|
+
DropDuplicates(keep="first"),
|
|
148
|
+
])
|
|
149
|
+
|
|
150
|
+
# Run with full result tracking
|
|
151
|
+
result = engine.run_with_result(df, dry_run=False)
|
|
152
|
+
print(result.summary())
|
|
153
|
+
print(result.audit_log)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Architecture & Design
|
|
159
|
+
|
|
160
|
+
`sanitizepy` adopts the following transparent workflow:
|
|
161
|
+
**Detect → Explain → Recommend → Preview → Apply → Validate → Audit**
|
|
162
|
+
|
|
163
|
+
```text
|
|
164
|
+
┌───────────────────────┐
|
|
165
|
+
│ Dataset │
|
|
166
|
+
└───────────┬───────────┘
|
|
167
|
+
│
|
|
168
|
+
┌─────────────┴─────────────┐
|
|
169
|
+
│ Dataset Profiler / │
|
|
170
|
+
│ Issue Detector │ (Read-Only)
|
|
171
|
+
└─────────────┬─────────────┘
|
|
172
|
+
│
|
|
173
|
+
┌─────────────┴─────────────┐
|
|
174
|
+
│ Recommendation Engine │ (Explainable)
|
|
175
|
+
└─────────────┬─────────────┘
|
|
176
|
+
│
|
|
177
|
+
┌─────────────┴─────────────┐
|
|
178
|
+
│ Cleaning Plan │ (Previewable)
|
|
179
|
+
└─────────────┬─────────────┘
|
|
180
|
+
│
|
|
181
|
+
user approves
|
|
182
|
+
│
|
|
183
|
+
┌─────────────┴─────────────┐
|
|
184
|
+
│ Transformation Engine │ (Deterministic)
|
|
185
|
+
└─────────────┬─────────────┘
|
|
186
|
+
│
|
|
187
|
+
┌─────────────┴─────────────┐
|
|
188
|
+
│ Validation / Audit │ (Auditable)
|
|
189
|
+
└───────────────────────────┘
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Documentation
|
|
195
|
+
|
|
196
|
+
Detailed documentation is available in the `docs/` directory:
|
|
197
|
+
|
|
198
|
+
- [Installation Guide](docs/installation.md): Requirements, virtual environments, installation commands, verification, and upgrade procedures.
|
|
199
|
+
- [Quick Start Guide](docs/quickstart.md): Step-by-step examples for inspection, cleaning, feature engineering, rules, reporting, and pipelines.
|
|
200
|
+
- [API Reference](docs/api.md): Complete technical API documentation for classes, functions, dataclasses, models, and exceptions.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Development & Testing
|
|
205
|
+
|
|
206
|
+
To run the project test suite or linting tools:
|
|
207
|
+
|
|
208
|
+
### Run Tests
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
pytest
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Code Formatting & Linting
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
black --check src tests
|
|
218
|
+
ruff check src tests
|
|
219
|
+
mypy src
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
`sanitizepy` is distributed under the terms of the [MIT License](LICENSE).
|
|
227
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=80", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sanitizepy"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "An open-source Python engine for automated tabular data quality inspection, explainable cleaning, and preprocessing."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Syed Muhammad Taha Hassan" }
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
keywords = [
|
|
18
|
+
"machine-learning",
|
|
19
|
+
"data-quality",
|
|
20
|
+
"data-cleaning",
|
|
21
|
+
"eda",
|
|
22
|
+
"feature-engineering",
|
|
23
|
+
"preprocessing",
|
|
24
|
+
"pandas",
|
|
25
|
+
"python",
|
|
26
|
+
"data-analysis"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
classifiers = [
|
|
30
|
+
"Development Status :: 3 - Alpha",
|
|
31
|
+
"Intended Audience :: Developers",
|
|
32
|
+
"Intended Audience :: Science/Research",
|
|
33
|
+
"Operating System :: OS Independent",
|
|
34
|
+
"Programming Language :: Python :: 3",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
39
|
+
"Topic :: Software Development :: Libraries"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
dependencies = [
|
|
43
|
+
"numpy>=1.24.0,<2.3.0",
|
|
44
|
+
"pandas>=2.0.0",
|
|
45
|
+
"scipy>=1.10.0",
|
|
46
|
+
"rich>=13.0.0",
|
|
47
|
+
"pydantic>=2.0.0"
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.optional-dependencies]
|
|
51
|
+
|
|
52
|
+
dev = [
|
|
53
|
+
"black>=24.0.0",
|
|
54
|
+
"ruff>=0.4.0",
|
|
55
|
+
"mypy>=1.10.0",
|
|
56
|
+
"pandas-stubs>=2.0.0",
|
|
57
|
+
"pytest>=8.0.0",
|
|
58
|
+
"pytest-cov>=5.0.0"
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[tool.setuptools]
|
|
62
|
+
package-dir = { "" = "src" }
|
|
63
|
+
|
|
64
|
+
[tool.setuptools.packages.find]
|
|
65
|
+
where = ["src"]
|
|
66
|
+
|
|
67
|
+
[tool.black]
|
|
68
|
+
line-length = 88
|
|
69
|
+
target-version = ["py311"]
|
|
70
|
+
|
|
71
|
+
[tool.ruff]
|
|
72
|
+
line-length = 88
|
|
73
|
+
target-version = "py311"
|
|
74
|
+
|
|
75
|
+
[tool.ruff.lint]
|
|
76
|
+
select = [
|
|
77
|
+
"E",
|
|
78
|
+
"F",
|
|
79
|
+
"I",
|
|
80
|
+
"N",
|
|
81
|
+
"UP",
|
|
82
|
+
"B",
|
|
83
|
+
"SIM",
|
|
84
|
+
"C4"
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
ignore = []
|
|
88
|
+
|
|
89
|
+
[tool.mypy]
|
|
90
|
+
python_version = "3.11"
|
|
91
|
+
strict = true
|
|
92
|
+
warn_return_any = true
|
|
93
|
+
warn_unused_configs = true
|
|
94
|
+
warn_unused_ignores = true
|
|
95
|
+
disallow_untyped_defs = true
|
|
96
|
+
disallow_incomplete_defs = true
|
|
97
|
+
check_untyped_defs = true
|
|
98
|
+
no_implicit_optional = true
|
|
99
|
+
|
|
100
|
+
[tool.pytest.ini_options]
|
|
101
|
+
pythonpath = [
|
|
102
|
+
"src"
|
|
103
|
+
]
|
|
104
|
+
testpaths = [
|
|
105
|
+
"tests"
|
|
106
|
+
]
|
|
107
|
+
addopts = "-ra"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
sanitizepy
|
|
3
|
+
|
|
4
|
+
An open-source Python engine for automated tabular data quality inspection,
|
|
5
|
+
explainable cleaning, and preprocessing.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from .api import (
|
|
11
|
+
DEFAULT_CONFIG,
|
|
12
|
+
VERSION,
|
|
13
|
+
VERSION_INFO,
|
|
14
|
+
Cleaner,
|
|
15
|
+
CleanerConfig,
|
|
16
|
+
CleanerError,
|
|
17
|
+
CleaningEngine,
|
|
18
|
+
CleaningPlan,
|
|
19
|
+
CleaningResult,
|
|
20
|
+
ConfigurationError,
|
|
21
|
+
DatasetHealthReport,
|
|
22
|
+
DatasetIssue,
|
|
23
|
+
DataValidationError,
|
|
24
|
+
EngineError,
|
|
25
|
+
OperationResult,
|
|
26
|
+
clean,
|
|
27
|
+
get_version,
|
|
28
|
+
inspect,
|
|
29
|
+
plan,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"Cleaner",
|
|
34
|
+
"inspect",
|
|
35
|
+
"plan",
|
|
36
|
+
"clean",
|
|
37
|
+
"DatasetHealthReport",
|
|
38
|
+
"DatasetIssue",
|
|
39
|
+
"CleaningPlan",
|
|
40
|
+
"CleaningResult",
|
|
41
|
+
"OperationResult",
|
|
42
|
+
"CleaningEngine",
|
|
43
|
+
"CleanerConfig",
|
|
44
|
+
"DEFAULT_CONFIG",
|
|
45
|
+
"CleanerError",
|
|
46
|
+
"ConfigurationError",
|
|
47
|
+
"DataValidationError",
|
|
48
|
+
"EngineError",
|
|
49
|
+
"VERSION",
|
|
50
|
+
"VERSION_INFO",
|
|
51
|
+
"get_version",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
__version__ = VERSION
|