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.2.tar.gz
(11.5 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.2.tar.gz.
File metadata
- Download URL: checkedframe-0.0.2.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cca4cc691b733e88ba92e0d29a7aa44a9388787a65f189b31971af8c71568767
|
|
| MD5 |
13f35074785058bf9b26688a052bdbb2
|
|
| BLAKE2b-256 |
2c2b938242b1880a0662dda1286c4eb2251721738111d0046fbfec47be022e09
|
File details
Details for the file checkedframe-0.0.2-py3-none-any.whl.
File metadata
- Download URL: checkedframe-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.9 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 |
afb04430da367cdd6167e1bd0c3a294b132d269d6d7e4f9deb991fbd0407e5d7
|
|
| MD5 |
af92899e3d2d98d553bb8468d2d66644
|
|
| BLAKE2b-256 |
c7e4c89b21ca2cf569eefcdf23783038e68910917c83a5133a5eed6a55f3fedb
|