Declarative data cleaning contracts for pandas.
Project description
cleanframe
Declarative data cleaning contracts for pandas. Annotation-based. Zero API calls. Offline-first.
from cleanframe import clean, Col, Schema
schema = Schema(
age = Col(null="median", clip=(0, 120)),
salary = Col(null="median", clip=(0, 999_999)),
dept = Col(null="Unknown", dtype="category"),
)
@clean(schema)
def train_model(df):
model.fit(df)
result = train_model(dirty_df)
print(result.explain())
print(result.to_code())
Install
pip install cleanframe
Decorators
| Decorator | What it does |
|---|---|
@clean(schema) |
Cleans the DataFrame before the function runs, returns a CleanResult |
@validate(schema) |
Raises DataQualityError if data is dirty — never modifies |
@audit(schema) |
Like @clean but also prints a full change log |
@profile |
Prints a data quality report, no schema needed |
@pipeline(s1, s2, ...) |
Applies multiple schemas in sequence |
Col() options
Col(
null="median", # mean | median | mode | drop | ffill | bfill | auto | ignore | <scalar>
clip=(0, 120), # clip numeric values to [min, max]
dtype="float", # int | float | str | bool | category | datetime
rename="age_yr", # rename column after cleaning
required=True, # raise KeyError if column is missing
)
CleanResult
result.df # cleaned DataFrame
result.explain() # human-readable change report
result.to_code() # equivalent pandas code (no cleanframe dependency)
result.summary() # one-line summary
result.return_value # what your function returned
Modes
@clean(schema, mode="fix") # default — clean silently
@clean(schema, mode="warn") # clean and emit UserWarning per change
@clean(schema, mode="raise") # raise DataQualityError instead of cleaning
Requirements
- Python >= 3.8
- pandas >= 1.3
- numpy >= 1.21
License
MIT
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
pycleanframe-1.0.0.tar.gz
(16.2 kB
view details)
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 pycleanframe-1.0.0.tar.gz.
File metadata
- Download URL: pycleanframe-1.0.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ce244c204031e880a784b950094e2767b84dc13a76adffa0f9011355f0bd8d7
|
|
| MD5 |
02260aff0f0868555cf09a4ef708a9b1
|
|
| BLAKE2b-256 |
eb07eb54a7ebb7b9fda2fcb0cfef3037f2115e66a47c1d66033796a14356f8ac
|
File details
Details for the file pycleanframe-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pycleanframe-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
551945ee17a2c7c584b5357eeb67769de625f001b74b9d70a3f9c295c0de4657
|
|
| MD5 |
eb97e2b161161236e6b591a1b13f0608
|
|
| BLAKE2b-256 |
8e7a70da34cbe5bf12690e1747fc3342a60055bf524e83faea895649210e183a
|