Skip to main content

A generic dataframe validation library

Project description

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


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.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

checkedframe-0.0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file checkedframe-0.0.1.tar.gz.

File metadata

  • Download URL: checkedframe-0.0.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for checkedframe-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c17d0d4db8f691f44f482721227235cb4f5b8432a8d5f77f33b700b1dd493dd0
MD5 536dc76f7504fd575ed4a44558018e0e
BLAKE2b-256 dea93f9ecebf470e3082e139ecb4487678b1c54a1a065a25ab152e66286e7f34

See more details on using hashes here.

File details

Details for the file checkedframe-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: checkedframe-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for checkedframe-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff7f9a29c806fe03bf08d9480e34e1b78289c3234a38ad2560e1066d77b7666f
MD5 adee5eabd03e1355ffc72812f1e2e5b0
BLAKE2b-256 d90185c788fd6479f829b1ad201276e18cdad41fadd3a199fcd45ab3ce5cb23a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page