A generic dataframe validation library
Project description
checkedframe:
What is it?
checkedframe is a lightweight library for DataFrame validation built on top of narwhals.
Why use checkedframe?
Usage:
Installing
The easiest way is to install checkedframe is from PyPI using pip:
pip install checkedframe
Examples
import checkedframe as cf
import polars as pl
from checkedframe.polars import DataFrame
class AASchema(cf.Schema):
reason_code = cf.Column(cf.String)
reason_code_description = cf.Column(cf.String, nullable=True)
shap = cf.Column(cf.Float64, cast=True)
rank = cf.Column(cf.UInt8, cast=True)
@cf.Check(column="reason_code")
def check_reason_code_length(s: pl.Series) -> pl.Series:
"""Reason codes must be exactly 3 chars"""
return s.str.len_bytes() == 3
@cf.Check(column="reason_code")
def check_is_id(s: pl.Series) -> bool:
"""Reason code must uniquely identify dataset"""
return s.n_unique() == s.len()
@cf.Check
def check_row_height(df: pl.DataFrame) -> bool:
"""DataFrame must have 2 rows"""
return df.height == 2
df = pl.DataFrame({
"reason_code": ["abc", "abc", "o9"],
"reason_code_description": ["a desc here", "another desc", None],
"shap": [1, 2, 3],
"rank": [-1, 2, 1]
})
df: DataFrame[AASchema] = AASchema.validate(df)
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
checkedframe-0.0.3.tar.gz
(12.4 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 checkedframe-0.0.3.tar.gz.
File metadata
- Download URL: checkedframe-0.0.3.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d8c5332151b02606f5e3903192a4c01f2e75704ec504552d6fde378560e08ae
|
|
| MD5 |
e28eb05aad76ae965729b355c6dedb98
|
|
| BLAKE2b-256 |
51ad749428d546c43a076c77ed0fb0f040b8464dc75ad032cda35feb9518a2e0
|
File details
Details for the file checkedframe-0.0.3-py3-none-any.whl.
File metadata
- Download URL: checkedframe-0.0.3-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
099263d3ce502a422581741d3bf00b0cf68f14a2f82b8516e1704ed4c1e78fb6
|
|
| MD5 |
0a2bdf2e60fd26b52f482700c5e40848
|
|
| BLAKE2b-256 |
fdcd91966860ad59c65395cba2122110702ca684d4954bca0bbc2cf757dd47a5
|