How tahahssn/sanitizepy works
Purpose and Entry Points
sanitizepy is a Python 3.11+ library for pandas dataset inspection, explainable cleaning, feature preprocessing, validation, reporting, and workflow orchestration. Primary public entry points are Cleaner plus module-level inspect, plan, and clean conveniences in src/sanitizepy/__init__.py and src/sanitizepy/api.py. src/sanitizepy/core.py coordinates the high-level Detect → Explain → Recommend → Preview → Apply → Validate → Audit flow.
Core Facade and Configuration
Cleaner owns the user-facing lifecycle: inspect a DataFrame, derive a cleaning plan from results, and execute it in dry-run or apply mode. Shared configuration, constants, type definitions, and domain exceptions establish common behavior across engines.
• src/sanitizepy/core.py
• src/sanitizepy/config.py
• src/sanitizepy/types.py
Read-Only Inspection and Health Modeling
Inspection is deliberately separated from mutation. Specialized inspectors analyze missingness, duplicates, dtypes, memory, and statistics; their outputs feed dataset-health evaluation and structured inspection models. This boundary makes diagnosis reproducible before a cleaning plan is generated.
• src/sanitizepy/inspection/health.py
• src/sanitizepy/inspection/detector.py
• src/sanitizepy/models/inspection.py
Recommendations, Rules, and Planning
Issue detection and the rules subsystem classify findings by category and severity, then produce explainable recommendations. A CleaningPlan represents the previewable, user-adjustable bridge between recommendations and executable operations; steps can be enabled or disabled before changes occur.
• src/sanitizepy/models/recommendations.py
• src/sanitizepy/rules/engine.py
• src/sanitizepy/cleaning/plan.py
Deterministic Cleaning and Audit Boundary
The cleaning engine applies operations such as missing-value handling, duplicate removal, and column removal to pandas DataFrames. Execution supports dry runs, impact/result capture, and immutable/serializable audit information, separating proposed or simulated changes from applied transformations.
• src/sanitizepy/cleaning/engine.py
• src/sanitizepy/cleaning/operations.py
• src/sanitizepy/cleaning/base.py
Stateful Preprocessing
Feature engineering is a parallel transformation subsystem rather than part of the cleaning-plan path. Its operations use fit/transform semantics for interactions, ratios, polynomial, logarithmic, and datetime-derived features while preserving DataFrame index behavior.
• src/sanitizepy/preprocessing/engine.py
• src/sanitizepy/preprocessing/operations.py
• src/sanitizepy/preprocessing/base.py
Reports and Pipeline Orchestration
Report models are rendered as text or JSON and exported to strings or files. The pipeline engine sequences callable or transform steps, recording duration and dataset-shape metadata; it can compose inspection, cleaning, preprocessing, or user-defined stages without requiring a server runtime.
• src/sanitizepy/reports/engine.py
• src/sanitizepy/reports/renderers.py
• src/sanitizepy/pipeline/engine.py
Runtime and External Boundaries
The runtime is local, in-process Python over pandas DataFrames. Material dependencies are pandas and NumPy for tabular/numerical work, SciPy for statistical capabilities, Pydantic for structured models, and Rich for terminal presentation. The repository exposes no database, web service, queue, or cloud infrastructure boundary; distribution is through PyPI and automation is defined in .github/workflows/ci.yml and .github/workflows/release.yml.
Main entry points: core.py Cleaner facade · cleaning/engine.py Cleaning engine · preprocessing/engine.py Preprocessing engine · pipeline/engine.py Pipeline engine
Components 19
Public API
- Convenience API · Module-level inspect, plan, and clean helpers.
src/sanitizepy/api.py - Cleaner facade · Coordinates detect through audit.
src/sanitizepy/core.py - Shared config & types
src/sanitizepy/config.py
Inspection & Planning
- Specialized detectors · Analyzes missingness, duplicates, dtypes, memory, and statistics.
src/sanitizepy/inspection/detector.py - Dataset health
src/sanitizepy/inspection/health.py - Inspection models
src/sanitizepy/models/inspection.py - Rules engine · Classifies findings by category and severity.
src/sanitizepy/rules/engine.py - Recommendations
src/sanitizepy/models/recommendations.py - Cleaning plan · Steps can be enabled or disabled before execution.
src/sanitizepy/cleaning/plan.py
Cleaning
- Cleaning engine · Supports dry runs, impacts, results, and applied changes.
src/sanitizepy/cleaning/engine.py - Cleaning operations · Handles missing values, duplicates, and column removal.
src/sanitizepy/cleaning/operations.py - Cleaning audit contracts · Defines serializable audit and operation contracts.
src/sanitizepy/cleaning/base.py
Transforms & Delivery
- Preprocessing engine · Runs fit/transform feature workflows independently of cleaning plans.
src/sanitizepy/preprocessing/engine.py - Feature operations · Interactions, ratios, polynomial, log, and datetime features.
src/sanitizepy/preprocessing/operations.py - Transform contracts · Preserves DataFrame index behavior.
src/sanitizepy/preprocessing/base.py - Pipeline engine · Sequences callable or transform stages with timing and shape metadata.
src/sanitizepy/pipeline/engine.py - Report engine · Exports report models to strings or files.
src/sanitizepy/reports/engine.py - Text & JSON renderers
src/sanitizepy/reports/renderers.py
Other components
- Local Python runtime · In-process pandas/NumPy execution; SciPy, Pydantic, and Rich support statistics, models, and presentation.
Connections 24
- Convenience API → Cleaner facade: delegates to
- Cleaner facade → Shared config & types: uses
- Cleaner facade → Specialized detectors: inspect
- Specialized detectors → Dataset health: findings feed
- Specialized detectors → Inspection models: produces
- Dataset health → Inspection models: records
- Cleaner facade → Rules engine: explains findings
- Inspection models → Rules engine: input
- Rules engine → Recommendations: produces
- Recommendations → Cleaning plan: becomes
- Cleaner facade → Cleaning plan: derives and previews
- Cleaning plan → Cleaning engine: executes
- Cleaning engine → Cleaning operations: applies
- Cleaning engine → Cleaning audit contracts: captures audit
- Preprocessing engine → Feature operations: runs
- Preprocessing engine → Transform contracts: uses contracts
- Pipeline engine → Cleaner facade: can compose
- Pipeline engine → Cleaning engine: can stage
- Pipeline engine → Preprocessing engine: can stage
- Report engine → Text & JSON renderers: renders through
- Cleaner facade → Report engine: reports results
- Local Python runtime → Cleaner facade: pandas DataFrames
- Local Python runtime → Cleaning engine: tabular runtime
- Local Python runtime → Preprocessing engine: tabular runtime