Skip to main content

Validate you Generic polars dataframes

Project description

DataFrame Extension for Polars

This package provides a generic extension to Polars DataFrame, allowing schema validation and custom validation logic through class-based definitions.

Features

  • Generic DataFrame: Ensures type safety using Python's TypedDict.
  • Schema Validation: Automatically checks that the DataFrame conforms to the expected schema.
  • Custom Validation Hooks: Define additional validation methods prefixed with check_.
  • Improved Typing for Rows: Provides better type safety for rows(named=True).

Installation

This package depends on polars. Install it with:

pip install polaric

Usage

Defining a Schema

Schemas are defined using Python's TypedDict:

from typing import TypedDict
from polaric import DataFrame
import polars as pl

class BasicSchema(TypedDict):
    a: int

df = pl.DataFrame({"a": [0, 1]})
basic_df = DataFrame[BasicSchema](df)
basic_df.validate()  # Ensures schema correctness

Adding Custom Validations

Extend DataFrame and define validation methods prefixed with check_:

class BasicSchemaDataFrame(DataFrame[BasicSchema]):
    def check_a_is_positive(self) -> Self:
        assert self.select(pl.col("a").ge(0).all()).item(), "Column a contains negative values!"
        return self

# Example usage
df = pl.DataFrame({"a": [0, 1]})
basic_df = BasicSchemaDataFrame(df)
basic_df.validate()  # Passes validation

# This will raise an AssertionError
df_invalid = pl.DataFrame({"a": [-1, 1]})
BasicSchemaDataFrame(df_invalid).validate()

Get typing goodies !

Ensure row retrieval maintains proper types:

row = basic_df.rows(named=True)[0]
# row is a typedDict !

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

polaric-0.1.0.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

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

polaric-0.1.0-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file polaric-0.1.0.tar.gz.

File metadata

  • Download URL: polaric-0.1.0.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.28

File hashes

Hashes for polaric-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0e97adc2c1ecc513433872785b58c259966d5149ec89c99f0e06f856e2b43d3
MD5 f6e4fcff29f9b069eadf30e0dc1f2d2c
BLAKE2b-256 6ab65e7494c86b288c36e671c8f1c7a7fbfc1f865a6d0f35875e644fa50c58fb

See more details on using hashes here.

File details

Details for the file polaric-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: polaric-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.28

File hashes

Hashes for polaric-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fab4b5f2a173da757168de74ebf356137184c920c7aff4f07604c2170a4a19fb
MD5 a220b952af709bb5ae0ffbdd234813db
BLAKE2b-256 2cfac40575fa3bf13114acc7441e3c5e253c987da5f7e4e619bd9fdf52fad815

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