Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Function decorators for Pandas Dataframe column name and data type validation

License

NotificationsYou must be signed in to change notification settings

ThoughtWorksInc/daffy

Repository files navigation

PyPIPyPI - Python Versiontestcodecov

Description

Working with DataFrames often means passing them through multiple transformation functions, making it easy to lose track of their structure over time. Daffy adds runtime validation and documentation to your DataFrame operations through simple decorators. By declaring the expected columns and types in your function definitions, you can:

@df_in(columns=["price","bedrooms","location"])@df_out(columns=["price_per_room","price_category"])defanalyze_housing(houses_df):# Transform raw housing data into price analysisreturnanalyzed_df

Like type hints for DataFrames, Daffy helps you catch structural mismatches early and keeps your data pipeline documentation synchronized with the code. Compatible with both Pandas and Polars.

Key Features

  • Validate DataFrame columns at function entry and exit points
  • Support regex patterns for matching column names (e.g.,"r/column_\d+/")
  • Check data types of columns
  • Control strictness of validation (allow or disallow extra columns)
  • Works with both Pandas and Polars DataFrames
  • Project-wide configuration via pyproject.toml
  • Integrated logging for DataFrame structure inspection
  • Enhanced type annotations for improved IDE and type checker support

Documentation

Installation

Install with your favorite Python dependency manager:

pip install daffy

Quick Start

fromdaffyimportdf_in,df_out@df_in(columns=["Brand","Price"])# Validate input DataFrame columns@df_out(columns=["Brand","Price","Discount"])# Validate output DataFrame columnsdefapply_discount(cars_df):cars_df=cars_df.copy()cars_df["Discount"]=cars_df["Price"]*0.1returncars_df

License

MIT

About

Function decorators for Pandas Dataframe column name and data type validation

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp