Skip to main content

Ergonomic inline validation for Polars DataFrames with pipeable assertions and user-friendly wrappers around native Polars boolean expressions.

Project description

checkpl

Ergonomic inline validation for Polars DataFrames.

Installation

pip install checkpl

Quick Start

import polars as pl
from assert_polars import verify, is_uniq

df = pl.DataFrame({
    "id": [1, 2, 3],
    "city": ["NYC", "LA", "NYC"],
    "year": [2020, 2020, 2021]
})

# Validate with Polars expressions
df.pipe(verify(pl.col("year") >= 2020))

# Validate uniqueness
df.pipe(verify(is_uniq("id")))

# Composite key uniqueness
df.pipe(verify(is_uniq("city", "year")))

# Chain validations
(
    df
    .pipe(verify(pl.col("year") >= 2020))
    .pipe(verify(is_uniq("id")))
    .filter(pl.col("city") == "NYC")
)

Features

  • Pipeable: Integrates with Polars' .pipe() for fluent data pipelines
  • Native expressions: Use any Polars boolean expression directly
  • Predicates: Built-in checks like is_uniq() for common validations
  • Clear errors: CheckError with descriptive messages and failure counts
  • LazyFrame support: Works with both DataFrame and LazyFrame

API

verify(check)

Validate a DataFrame using a Polars expression or predicate.

# With Polars expression
df.pipe(verify(pl.col("price") > 0))

# With predicate
df.pipe(verify(is_uniq("id")))

Raises CheckError if validation fails, returns DataFrame unchanged if valid.

is_uniq(*cols)

Check that column(s) have no duplicate values.

df.pipe(verify(is_uniq("id")))           # Single column
df.pipe(verify(is_uniq("id", "year")))   # Composite key

Error Handling

from assert_polars import CheckError

try:
    df.pipe(verify(is_uniq("id")))
except CheckError as e:
    print(f"Check '{e.check_name}' failed: {e}")

License

MIT

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assert_polars-0.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

assert_polars-0.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file assert_polars-0.2.tar.gz.

File metadata

  • Download URL: assert_polars-0.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for assert_polars-0.2.tar.gz
Algorithm Hash digest
SHA256 499a617ae6c72b8511cca5c7c3ea77ae2838f2089c279497d71eddf08aae68db
MD5 c3ce9e1d6bdae105de3547fdf28debcf
BLAKE2b-256 2dcf9eb34e3910fb230b64efbef68617d40dda1e3539b3d3f42334361dee5c57

See more details on using hashes here.

File details

Details for the file assert_polars-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for assert_polars-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99abc7c349f6fba188ef6adabd3856cb32fd1e34308156c338ac9cb7de94ae64
MD5 1d44f2707a37f6e24acb30f9c6957b8b
BLAKE2b-256 3df016c4f8cb2e485bc498dbfa4a88d45c178cfea3b96633504821d80b0851d0

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