Skip to main content

Function decorators for DataFrame validation - columns, data types, and row-level validation with Pydantic. Supports Pandas, Polars, Modin, and PyArrow.

Project description

Daffy — Validate pandas & Polars DataFrames with Python Decorators

PyPI conda-forge Python Docs CI codecov

Validate your pandas and Polars DataFrames at runtime with simple Python decorators. Daffy catches missing columns, wrong data types, and invalid values before they cause downstream errors in your data pipeline.

Also supports Modin and PyArrow DataFrames.

  • Column & dtype validation — lightweight, minimal overhead
  • Value constraints — nullability, uniqueness, range checks
  • Row validation with Pydantic — when you need deeper checks
  • Works with pandas, Polars, Modin, PyArrow — no lock-in

Installation

pip install daffy

or with conda:

conda install -c conda-forge daffy

Works with whatever DataFrame library you already have installed. Python 3.10–3.14.


Quickstart

from daffy import df_in, df_out

@df_in(["price", "bedrooms", "location"])
@df_out(["price_per_room", "price_category"])
def analyze_housing(houses_df):
    # Transform raw housing data into price analysis
    return analyzed_df

If a column is missing, has wrong dtype, or violates a constraint — Daffy fails fast with a clear error message at the function boundary.


Why Daffy?

Most DataFrame validation tools are schema-first (define schemas separately) or pipeline-wide (run suites over datasets). Daffy is decorator-first: validate inputs and outputs where transformations happen.

Non-intrusive Just add decorators — no refactoring, no custom DataFrame types, no schema files
Easy to adopt Add in 30 seconds, remove just as fast if needed
In-process No external stores, orchestrators, or infrastructure
Pay for what you use Column validation is essentially free; opt into row validation when needed

Examples

Column validation

from daffy import df_in, df_out

@df_in(["Brand", "Price"])
@df_out(["Brand", "Price", "Discount"])
def apply_discount(df):
    df = df.copy()
    df["Discount"] = df["Price"] * 0.1
    return df

Regex column matching

Match dynamic column names with regex patterns:

@df_in(["id", "r/feature_\\d+/"])
def process_features(df):
    return df

Value constraints

Vectorized checks with zero row iteration overhead:

@df_in({
    "price": {"checks": {"gt": 0, "lt": 10000}},
    "status": {"checks": {"isin": ["active", "pending", "closed"]}},
    "email": {"checks": {"str_regex": r"^[^@]+@[^@]+\.[^@]+$"}},
})
def process_orders(df):
    return df

Available checks: gt, ge, lt, le, between, eq, ne, isin, notnull, str_regex Also supported: notin, str_startswith, str_endswith, str_contains, str_length

Nullability and uniqueness

@df_in({
    "user_id": {"unique": True, "nullable": False},  # user_id must be unique and not null
    "email": {"nullable": False},  # email cannot be null
    "age": {"dtype": "int64"},
})
def clean_users(df):
    return df

Row validation with Pydantic

For complex, cross-field validation:

pip install 'daffy[pydantic]'
from pydantic import BaseModel, Field
from daffy import df_in

class Product(BaseModel):
    name: str
    price: float = Field(gt=0)
    stock: int = Field(ge=0)

@df_in(row_validator=Product)
def process_inventory(df):
    return df

Daffy vs Alternatives

Use Case Daffy Pandera Great Expectations
Function boundary guardrails ✅ Primary focus ⚠️ Possible ❌ Not designed for
Quick column/type checks ✅ Lightweight ⚠️ Requires schemas ⚠️ Requires setup
Complex statistical checks ⚠️ Limited ✅ Extensive ✅ Extensive
Pipeline/warehouse QA ❌ Not designed for ⚠️ Some support ✅ Primary focus
Multi-backend support ⚠️ Varies

Configuration

Configure Daffy project-wide via pyproject.toml:

[tool.daffy]
strict = true

Documentation

Full documentation available at daffy.readthedocs.io


Contributing

Issues and pull requests welcome on GitHub.

License

MIT

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

daffy-2.8.0.tar.gz (57.4 kB view details)

Uploaded Source

Built Distribution

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

daffy-2.8.0-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file daffy-2.8.0.tar.gz.

File metadata

  • Download URL: daffy-2.8.0.tar.gz
  • Upload date:
  • Size: 57.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for daffy-2.8.0.tar.gz
Algorithm Hash digest
SHA256 7849bca946eb0d6c09718d280873b84243d2859354a4c10796092a08c3683d28
MD5 a5ecdd5eea78ab1a6e97c54669708a96
BLAKE2b-256 6de006e75f6970b1754586d62f0790fc99082c0fb27fe008a84d252fe9d44263

See more details on using hashes here.

Provenance

The following attestation bundles were made for daffy-2.8.0.tar.gz:

Publisher: release.yml on vertti/daffy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file daffy-2.8.0-py3-none-any.whl.

File metadata

  • Download URL: daffy-2.8.0-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for daffy-2.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10b35da445a47bd2617e0ad3b1e977c3224be575febd27b62dba0b134456f97e
MD5 e9d540effa63c5dcfb885f62c5c180d5
BLAKE2b-256 9b3af7e0052821b01632ecb948557130dac7dcc47b3b0b937578f6e344f2cd43

See more details on using hashes here.

Provenance

The following attestation bundles were made for daffy-2.8.0-py3-none-any.whl:

Publisher: release.yml on vertti/daffy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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