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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| framehints-1.0.1.tar.gz | 3.4 kB | Without provenance | Details for framehints-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| framehints-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for framehints-1.0.1-py3-none-any.whl |
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
|
Security for framehints 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.