Skip to main content

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.

Python 3.9+ License: MIT Code style: black


โœจ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cleanix-0.1.0.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cleanix-0.1.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

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

Hashes for cleanix-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad85ed6450428f057765587ed9bdf6d20cda328484c8cefe5d36d3ed4b814291
MD5 3c7a32f5c02e69fb42ac28dad1a2310c
BLAKE2b-256 0f12ba147b841e0aacab283e8fe7476d142b6ba41d41611dcf91dbf0e6a80205

See more details on using hashes here.

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

Hashes for cleanix-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56685dc9232787c3240e6d35fd20087dbd80cb2fc9f123fcff97a1949fa65d9b
MD5 6d5ccc81af50b6a8b452272bad55be26
BLAKE2b-256 17b7b09e2961ad25d976105ffc52670973522622a6e3fe229c1cb81baf39987a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page