Skip to main content

A generic dataframe validation library

Project description

checkedframe:

PyPI version PyPI - Downloads License: MIT Tests

Documentation

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.String()
    reason_code_description = cf.String(nullable=True)
    shap = cf.Float64(cast=True)
    rank = 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.4.tar.gz (14.3 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.4-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: checkedframe-0.0.4.tar.gz
  • Upload date:
  • Size: 14.3 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.4.tar.gz
Algorithm Hash digest
SHA256 1d38e334e5d56da424b98a5627964296a17ce34be856b0b2c04b0412c59b6a8d
MD5 821ae2e03a34e440f6f6afbcb411d937
BLAKE2b-256 151d8fed345658d092ae70aa119e1dda475980bf46431d60d8e60c575b288b20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: checkedframe-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.0 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0aae77cc689ab0a81f43161a387f3a6383c8fcbca324428736a0977d4ef8e887
MD5 d6f05becf3ad1403fd4e721eaa0d56e5
BLAKE2b-256 0fc90c568415fe3bbb9e8fae35c45f1efdcbc2dceea97f15111c1da792b4b6fa

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