A library for dataset quality checks, preprocessing, and report generation
Project description
[!NOTE] HashPrep is now in its first stable release (v0.1.0). Core features are fully tested with CI.
Overview
HashPrep is a Python library for intelligent dataset profiling and debugging that acts as a comprehensive pre-training quality assurance tool for machine learning projects. Think of it as "Pandas Profiling + PyLint for datasets", designed specifically for machine learning workflows.
It catches critical dataset issues before they derail your ML pipeline, explains the problems, and suggests context-aware fixes.
If you want, HashPrep can even apply those fixes for you automatically.
Features
Key features include:
- Intelligent Profiling: Detect missing values, skewed distributions, outliers, and data type inconsistencies.
- ML-Specific Checks: Identify data leakage, dataset drift, class imbalance, and high-cardinality features.
- Automated Preparation: Get suggestions for encoding, imputation, scaling, and transformations.
- Rich Reporting: Generate statistical summaries and exportable reports (HTML/PDF/Markdown/JSON) with embedded visualizations.
- Production-Ready Pipelines: Output reproducible cleaning and preprocessing code (
fixes.py) that integrates seamlessly with ML workflows. - Modern Themes: Choose between "Minimal" (professional) and "Neubrutalism" (bold) report styles.
Installation
Using pip
pip install hashprep
Using uv (recommended)
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install hashprep
uv pip install hashprep
# Or for development from source
git clone https://github.com/cachevector/hashprep.git
cd hashprep
uv sync
After installation, the hashprep command will be available directly in your terminal.
Usage
HashPrep can be used both as a command-line tool and as a Python library.
CLI Usage
1. Quick Scan
Get a quick summary of critical issues in your terminal.
hashprep scan dataset.csv
Options:
--critical-only: Show only critical issues--quiet: Minimal output (counts only)--json: Output in JSON format--target COLUMN: Specify target column for ML-specific checks--checks CHECKS: Run specific checks (comma-separated)--comparison FILE: Compare with another dataset for drift detection--sample-size N: Limit analysis to N rows--no-sample: Disable automatic sampling--config FILE: Load thresholds from a YAML/TOML/JSON config file
Example:
# Scan with target column and specific checks
hashprep scan train.csv --target Survived --checks outliers,high_missing_values,class_imbalance
# Quick scan with JSON output
hashprep scan dataset.csv --json --quiet
2. Detailed Analysis
Get comprehensive details about all detected issues.
hashprep details dataset.csv
Options: Same as scan command (including --config)
Example:
hashprep details train.csv --target Survived
3. Generate Reports
Generate comprehensive reports in multiple formats with visualizations.
hashprep report dataset.csv --format html --theme minimal
Options:
--output PATH,-o PATH: Custom output file path--format {md,json,html,pdf}: Report format (default: md)--theme {minimal,neubrutalism}: HTML report theme (default: minimal)--with-code: Generate Python scripts for fixes and pipelines--full/--no-full: Include/exclude full summaries (default: True)--visualizations/--no-visualizations: Include/exclude plots (default: True)--target COLUMN: Specify target column--checks CHECKS: Run specific checks--comparison FILE: Compare with another dataset for drift detection--sample-size N: Limit analysis to N rows--no-sample: Disable automatic sampling--config FILE: Load thresholds from a YAML/TOML/JSON config file
Examples:
# Generate HTML report with minimal theme
hashprep report dataset.csv --format html --theme minimal --full
# Generate PDF report without visualizations (faster)
hashprep report dataset.csv --format pdf --no-visualizations
# Generate report with automatic fix scripts
hashprep report dataset.csv --with-code
# Generate report with custom output path
hashprep report dataset.csv --format html --output my_reports/analysis.html
# This creates:
# - dataset_hashprep_report.md (or .html/.pdf/.json)
# - dataset_hashprep_report_fixes.py (pandas script)
# - dataset_hashprep_report_pipeline.py (sklearn pipeline)
# Compare two datasets for drift detection
hashprep report train.csv --comparison test.csv --format html
4. List Available Checks
Discover all data quality checks that HashPrep can perform.
hashprep checks
5. Version
Check HashPrep version.
hashprep version
Available Checks
outliers- Detect outliers using z-scoreduplicates- Find duplicate rowshigh_missing_values- Columns with high missing dataempty_columns- Completely empty columnsdataset_missingness- Overall missing data patternsmissing_patterns- Correlated missing value patternshigh_cardinality- Categorical columns with too many unique valuessingle_value_columns- Constant columns with no variancemixed_data_types- Columns with mixed data typesclass_imbalance- Imbalanced target variable (requires --target)feature_correlation- Highly correlated numeric featurescategorical_correlation- Highly associated categorical featuresmixed_correlation- Numeric-categorical associationsdata_leakage- Columns identical to targettarget_leakage_patterns- Features that may leak target informationdataset_drift- Distribution drift between datasets (requires --comparison)uniform_distribution- Uniformly distributed numeric columnsunique_values- Columns where >95% values are uniquehigh_zero_counts- Columns with excessive zero valuesskewness- Highly skewed numeric distributionsinfinite_values- Columns containing infinite valuesconstant_length- String columns with constant character lengthextreme_text_lengths- Text columns with extreme value lengthsdatetime_skew- Datetime columns concentrated in one perioddatetime_future_dates- Datetime columns with values in the futuredatetime_gaps- Anomalous gaps in datetime sequencesdatetime_monotonicity- Non-monotonic datetime columnsnormality- Non-normal numeric distributions (Shapiro-Wilk / D'Agostino-Pearson)variance_homogeneity- Unequal variances across target groups (Levene's test, requires --target)low_mutual_information- Features with near-zero mutual information with the target (requires --target)empty_dataset- Empty or all-missing datasets
Python Library Usage
Basic Analysis
import pandas as pd
from hashprep import DatasetAnalyzer
# Load your dataset
df = pd.read_csv("dataset.csv")
# Create analyzer
analyzer = DatasetAnalyzer(df)
# Run analysis
summary = analyzer.analyze()
# Access results
print(f"Critical issues: {summary['critical_count']}")
print(f"Warnings: {summary['warning_count']}")
# Iterate through issues
for issue in summary['issues']:
print(f"{issue['severity']}: {issue['description']}")
Analysis with Target Column
# Specify target for ML-specific checks
analyzer = DatasetAnalyzer(
df,
target_col='target_column'
)
summary = analyzer.analyze()
Run Specific Checks
# Only run specific checks
analyzer = DatasetAnalyzer(
df,
selected_checks=['outliers', 'high_missing_values', 'class_imbalance']
)
summary = analyzer.analyze()
Include Visualizations
# Generate analysis with plots
analyzer = DatasetAnalyzer(df, include_plots=True)
summary = analyzer.analyze()
# Plots are stored in summary['summaries']['plots']
Drift Detection
# Compare two datasets
train_df = pd.read_csv("train.csv")
test_df = pd.read_csv("test.csv")
analyzer = DatasetAnalyzer(
train_df,
comparison_df=test_df,
selected_checks=['dataset_drift']
)
summary = analyzer.analyze()
Generate Reports Programmatically
from hashprep.reports import generate_report
# Analyze dataset
analyzer = DatasetAnalyzer(df, include_plots=True)
summary = analyzer.analyze()
# Generate HTML report
generate_report(
summary,
format='html',
full=True,
output_file='report.html',
theme='minimal'
)
# Generate PDF report
generate_report(
summary,
format='pdf',
full=True,
output_file='report.pdf'
)
# Generate JSON report
generate_report(
summary,
format='json',
full=True,
output_file='report.json'
)
# Generate Markdown report
generate_report(
summary,
format='md',
full=True,
output_file='report.md'
)
Generate Fix Scripts
from hashprep.checks.core import Issue
from hashprep.preparers.codegen import CodeGenerator
from hashprep.preparers.pipeline_builder import PipelineBuilder
from hashprep.preparers.suggestions import SuggestionProvider
# After running analysis
analyzer = DatasetAnalyzer(df, target_col='target')
summary = analyzer.analyze()
# Convert issues to proper format
issues = [Issue(**i) for i in summary['issues']]
column_types = summary.get('column_types', {})
# Get suggestions
provider = SuggestionProvider(
issues=issues,
column_types=column_types,
target_col='target'
)
suggestions = provider.get_suggestions()
# Generate pandas fix script
codegen = CodeGenerator(suggestions)
fixes_code = codegen.generate_pandas_script()
with open('fixes.py', 'w') as f:
f.write(fixes_code)
# Generate sklearn pipeline
builder = PipelineBuilder(suggestions)
pipeline_code = builder.generate_pipeline_code()
with open('pipeline.py', 'w') as f:
f.write(pipeline_code)
Load Config from File
from hashprep.utils.config_loader import load_config
from hashprep import DatasetAnalyzer
# Load thresholds from YAML, TOML, or JSON
config = load_config("hashprep.yaml") # or .toml / .json
analyzer = DatasetAnalyzer(df, config=config)
summary = analyzer.analyze()
Example hashprep.yaml:
missing_values:
warning: 0.3
critical: 0.6
outliers:
z_score: 3.5
statistical_tests:
normality_p_value: 0.01
Only the keys you specify are overridden; all others fall back to defaults.
Custom Sampling
from hashprep.utils.sampling import SamplingConfig
# Configure sampling for large datasets
sampling_config = SamplingConfig(max_rows=10000)
analyzer = DatasetAnalyzer(
df,
sampling_config=sampling_config,
auto_sample=True
)
summary = analyzer.analyze()
# Check if sampling occurred
if 'sampling_info' in summary:
info = summary['sampling_info']
print(f"Sampled: {info['sample_fraction']*100:.1f}%")
License
This project is licensed under the MIT License.
Contributing
We welcome contributions from the community to make HashPrep better!
Before you get started, please:
- Review our CONTRIBUTING.md for detailed guidelines and setup instructions
- Write clean, well-documented code
- Follow best practices for the stack or component you’re working on
- Open a pull request (PR) with a clear description of your changes and motivation
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 hashprep-0.1.0.tar.gz.
File metadata
- Download URL: hashprep-0.1.0.tar.gz
- Upload date:
- Size: 75.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a3499385f51684c659169d62e21be8f665b210772342772fea9832f488157fb
|
|
| MD5 |
e6b5ffa6b31dd95b0c1ee0455f3f770f
|
|
| BLAKE2b-256 |
3ab743e541d660491721347432c203adcccb1367ed81558a3a6d5cfabc52c57e
|
File details
Details for the file hashprep-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hashprep-0.1.0-py3-none-any.whl
- Upload date:
- Size: 89.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6af61acdddec8e11dda371bd920e70c0c3d4b8250ce6478ec0da77b913ee54b7
|
|
| MD5 |
6248ff38a43b3a614235f90d550c1f3e
|
|
| BLAKE2b-256 |
9e53e717be9992e7ab2a1d397d98e8ca45fab8d14e9d45db618377868a6fc699
|