Skip to main content

framehints

Simple library (decorator & function) for validating Pandas Dataframes structure

Installation

pip install git+https://github.com/lutrarutra/framehints

Usage

from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
import numpy as np
import pandas as pd

import framehints as fh

@dataclass
class CustomClass():
    field1: int
    field2: str

schema = {
    "name": str,
    "value": float,
    "date": datetime | None,
    "path": Path | str,
    "data": np.ndarray | list | None,
    "custom": CustomClass,
    "column_that_doesnt_exists": int  # This column is optional, so it won't raise an error if it's missing
}

# Usage with function decorator
@fh.pdvalidate({"df": schema}, optional_columns={"df": ["column_that_doesnt_exists"]})
def your_function(df: pd.DataFrame):
    return df.shape


df = pd.DataFrame({
    'name': ['Alice', 'Bob', 'Charlie'],
    'value': [1.0, 2.5, 2.2],
    'date': [datetime.now(), datetime.now(), None],
    "path": [Path("/tmp"), Path("/var"), "/home"],
    "data": [np.zeros([1, 2]), None, [1,2,3]],
    "custom": [CustomClass(1, "a"), CustomClass(2, "b"), CustomClass(2, "b")]
})

try:
    your_function(df)
    print("1. DataFrame is valid.")
except TypeError as e:
    print(e)


# or usage with function
try:
    df = fh.validate_df(df, schema, optional_columns=["column_that_doesnt_exists"])
    print("2. DataFrame is valid.")
except TypeError as e:
    print(e)

Metadata

Release files for framehints 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for framehints 1.0.1
File Size Uploaded
framehints-1.0.1.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for framehints 1.0.1
File Interpreter ABI Platform
framehints-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.0 kB

Release files / framehints-1.0.1.tar.gz

Download URL framehints-1.0.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c6eb2bf7ccea0c0838129c86153183ae05d579bb922b5969fd6248eaf4096112
BLAKE2b-256 checksum
How to use checksums
cfa251cf0dea39430339ec6294135d258c98410e80b3c139c9178a5f606fd11a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / framehints-1.0.1-py3-none-any.whl

Download URL framehints-1.0.1-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbe8fd9f8b4b4f51de649a5e8dde2006d0f1e05fdef91e8acaf07fff8e243b91
BLAKE2b-256 checksum
How to use checksums
e94eed303f309d80dae31840d2cc444db579858a4d4a13fb198d9662949a5d54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page