Skip to main content

Validate you Generic polars dataframes

Project description

Polars on steroids!

This package provides a generic extension to Polars DataFrame, allowing data validation and typing goodies.

Features

  • Generic DataFrame: Ensures type safety using Python's TypedDict.
  • Data Validation: Checks that the DataFrame conforms to the expected schema.
  • Custom Checks: Leverage the power of polars expression to add custom checks.
  • Lightweight: No dependencies (except polars)!

Installation

pip install polaroids

Documentation

📖 Read the full documentation here: Project Documentation

Basic Usage

from typing import Annotated, TypedDict
from polaroids import DataFrame, Field
import polars as pl

class Schema(TypedDict):
    a: Annotated[int, Field(
        sorted="ascending",
        coerce=True,
        unique=True,
        checks=[lambda d: d.ge(0)],
    )]
    b: int | None

(
    pl.DataFrame({"a": [0.0, 1.0], "b": [None, 0]})   
    .pipe(DataFrame[Schema]) # <- Add a Schema to your dataframe
    .validate() # Validate it from the Schema annotations!
)
shape: (2, 2)
┌─────┬──────┐
 a    b    
 ---  ---  
 i64  i64  
╞═════╪══════╡
 0    null 
 1    0    
└─────┴──────┘

Typing Benefits with polaroids

One of the key advantages of polaroids is its strong typing support. You can use classic Polars functions while benefiting from improved type checking and autocompletion in your IDE, reducing runtime errors.

row = df.row(0, named=True)
row["a"]  # ✅ No issue if "a" exists
row["not_exists"] # ❌ Type error detected immediately!

Comparison with Alternatives

Compared to Pandera and Patito, polaroids' typing system is based on TypedDict rather than Pydantic's BaseModel.

Pydantic is a great tool, but when validating large Polars DataFrames, it's preferable to use Polars expressions for efficiency. Given this, a dependency on Pydantic is not particularly relevant.

Moreover, to benefit from typing with Pandera or Patito, you need to instantiate Pydantic objects, which introduces a runtime penalty, especially when iterating over rows.

In contrast, polaroids relies on stub-based typing, meaning there is no runtime penalty. As a result, polaroids is extremely lightweight, with no dependencies (neither Pandas nor Pydantic).

Contribution

We welcome contributions to polaroids! Follow these steps to set up your development environment and ensure your changes meet project standards.

1. Clone the Repository

git clone git@github.com:gab23r/polaroids.git
cd polaroids

2. Set Up the Environment

uv sync

3. Pre-commit Hooks

uv run pre-commit install

To manually run checks before committing:

uv run pre-commit run --all-files

4. Running Tests

uv run pytest tests

Thanks and happy coding! 🚀

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

polaroids-0.2.0.tar.gz (65.4 kB view details)

Uploaded Source

Built Distribution

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

polaroids-0.2.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file polaroids-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for polaroids-0.2.0.tar.gz
Algorithm Hash digest
SHA256 33cfd1540aee0b0c8cee8d092cf3469f6240b212c38e0c4d3a3d68c1352783d9
MD5 798b8a6921e99825ba2095cb1d09b270
BLAKE2b-256 dae1cec32c7931bf218b2755ca722bf7fbc90ec36f029194516add37559d13b3

See more details on using hashes here.

File details

Details for the file polaroids-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for polaroids-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85aa14d855a0f1e9e3978688ae62fe81709259cb016cc213dd7cf0caf8319f83
MD5 bcd3083e37996ca4cc1e7f58f28ea33f
BLAKE2b-256 9accd4a239a5a17dacdb839fea63952a7386c20a32f07f51cecc574469676c95

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