Metadata-Version: 2.4
Name: checkedframe
Version: 0.0.1
Summary: A generic dataframe validation library
Author-email: Cangyuan Li <everest229@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/CangyuanLi/checkedframe
Project-URL: Source, https://github.com/CangyuanLi/checkedframe
Project-URL: Bug Reports, https://github.com/CangyuanLi/checkedframe/issues
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: narwhals>=1.0.0
Dynamic: license-file

```python
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)
```
