Intelligent, explainable data cleaning built on pandas.
Project description
Cleanix
Intelligent, explainable data cleaning built on pandas.
Cleanix automatically detects and fixes common data-quality problems โ missing values, duplicates, wrong dtypes, and outliers โ and produces a human-readable report explaining every decision it made.
โจ Features
- ๐งน Automated Cleaning โ handles duplicates, missing values, data types, and outliers
- โ๏ธ Configurable โ customize every threshold via
CleaningConfig - ๐ Explainable โ detailed report of every action taken
- ๐ Preview Mode โ see what would be cleaned before applying
- ๐ก๏ธ Safe โ input validation, memory limits, and error recovery
- ๐ Quality Metrics โ before/after comparison of data quality
- ๐งช Well-Tested โ comprehensive test suite
๐ Quick Start
Installation
# From source
git clone https://github.com/cleanix/cleanix.git
cd cleanix
pip install -e ".[dev]"
Basic Usage
import pandas as pd
from cleanix import clean
df = pd.read_csv("your_dataset.csv")
cleaned_df, report = clean(df)
print(report.summary())
cleaned_df.to_csv("clean_data.csv", index=False)
Preview Changes First
from cleanix import suggest_cleaning
for s in suggest_cleaning(df):
print(f"[{s['priority']}] {s['message']}")
Custom Configuration
from cleanix import clean, CleaningConfig
config = CleaningConfig(
missing_drop_threshold=0.3, # drop columns with >30% missing
outlier_iqr_factor=2.0, # more lenient outlier detection
enable_duplicates=True,
verbose=True,
)
cleaned_df, report = clean(df, config)
๐ API Reference
clean(df, config=None) โ (DataFrame, Report)
Runs the full pipeline:
| Stage | What it does |
|---|---|
| 1. Duplicates | Drops exact duplicate rows |
| 2. Missing | Imputes or drops columns with NaN |
| 3. Data Types | Coerces object columns to better types |
| 4. Outliers | Caps outliers with the IQR method |
The original DataFrame is never mutated โ a fresh copy is returned.
suggest_cleaning(df, config=None) โ list[dict]
Preview what clean() would do, without modifying anything.
from cleanix import suggest_cleaning
for s in suggest_cleaning(df):
print(s["priority"], s["message"])
profile_data(df) โ dict[str, dict]
Per-column statistics: dtype, missing %, unique count, sample values.
from cleanix import profile_data
for col, info in profile_data(df).items():
print(f"{col}: {info['missing_pct']:.1%} missing")
CleaningConfig
from cleanix import CleaningConfig
config = CleaningConfig(
# Missing values
missing_drop_threshold=0.50, # drop if โฅ50% missing
# Type conversion
numeric_conversion_threshold=0.80, # convert if โฅ80% numeric
datetime_conversion_threshold=0.80, # convert if โฅ80% dates
category_unique_ratio=0.05, # convert if โค5% unique
category_min_rows=10,
# Outliers
outlier_iqr_factor=1.5, # IQR multiplier
outlier_min_rows=10, # skip if fewer rows
# Pipeline toggles
enable_duplicates=True,
enable_missing=True,
enable_datatypes=True,
enable_outliers=True,
# Safety
max_memory_mb=None, # None = no limit
verbose=False,
)
Report
| Method | Returns | Description |
|---|---|---|
.summary() |
str |
Human-readable, emoji-annotated summary |
.to_dict() |
dict |
Plain Python dict of all actions |
.to_json() |
str |
JSON-serialized report |
๐ง Cleaning Strategy
Missing Values
| Condition | Action |
|---|---|
| โฅ 50% missing | Drop column |
| Numeric | Fill with median |
| Categorical | Fill with mode |
| 100% missing | Drop column |
Data Types
| Condition | Action |
|---|---|
| โฅ 80% values numeric | Convert to float64 |
| โฅ 80% values datetime | Convert to datetime64 |
| Unique ratio โค 5% | Convert to category |
Outliers
- IQR method:
[Q1 โ 1.5รIQR, Q3 + 1.5รIQR] - Values outside fences are clipped (not dropped)
- Skipped on datasets with fewer than 10 rows
๐ Quality Metrics
from cleanix import clean, calculate_quality_metrics, format_quality_report
cleaned_df, report = clean(df)
metrics = calculate_quality_metrics(df, cleaned_df)
print(format_quality_report(metrics))
๐ก๏ธ Error Handling
from cleanix import clean, ValidationError, CleaningError
try:
cleaned_df, report = clean(df)
except ValidationError as e:
print(f"Bad input: {e}")
except CleaningError as e:
print(f"Pipeline failed: {e}")
Exception hierarchy:
CleanixError
โโโ ValidationError โ bad input
โโโ ConfigurationError โ bad config
โโโ CleaningError โ pipeline failure
โโโ MemoryLimitError โ exceeded memory limit
๐งช Running Tests
pip install -e ".[dev]"
pytest
pytest --cov=cleanix --cov-report=html # with coverage
๐ Project Layout
cleanix/
โโโ cleanix/ # Main package
โ โโโ __init__.py # Public API
โ โโโ cleaner.py # clean() orchestrator
โ โโโ config.py # CleaningConfig
โ โโโ exceptions.py # Custom exceptions
โ โโโ validation.py # Input validation
โ โโโ duplicates.py # Duplicate removal
โ โโโ missing.py # Missing value handling
โ โโโ datatypes.py # Type coercion
โ โโโ outliers.py # Outlier capping
โ โโโ profiler.py # profile_data()
โ โโโ suggester.py # suggest_cleaning()
โ โโโ report.py # Report class
โ โโโ metrics.py # Quality metrics
โโโ tests/ # Test suite
โโโ example_usage.py # Usage examples
โโโ pyproject.toml
โโโ CONTRIBUTING.md
โโโ README.md
๐ค Contributing
See CONTRIBUTING.md for setup and guidelines.
๐ License
MIT โ see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cleanix-0.1.0.tar.gz.
File metadata
- Download URL: cleanix-0.1.0.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad85ed6450428f057765587ed9bdf6d20cda328484c8cefe5d36d3ed4b814291
|
|
| MD5 |
3c7a32f5c02e69fb42ac28dad1a2310c
|
|
| BLAKE2b-256 |
0f12ba147b841e0aacab283e8fe7476d142b6ba41d41611dcf91dbf0e6a80205
|
File details
Details for the file cleanix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cleanix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56685dc9232787c3240e6d35fd20087dbd80cb2fc9f123fcff97a1949fa65d9b
|
|
| MD5 |
6d5ccc81af50b6a8b452272bad55be26
|
|
| BLAKE2b-256 |
17b7b09e2961ad25d976105ffc52670973522622a6e3fe229c1cb81baf39987a
|