Pandera-Tool
Pandera-Tool is a package for pandera.
- DataFrame type definition
- Validation
- Type coerce
Installation
pip install pandera-tool
Example
DataFrame type definition
from io import StringIO
from typing import Tuple
import pandas as pd
from pandera import Field, SchemaModel
from pandera.errors import SchemaError
from pandera.typing import Series
from pandera_tool import check_annotations, dtype, to_dataframe, to_schema
@to_dataframe
class DataFrameIn(SchemaModel):
Name: Series[str] = Field()
class Config:
strict = True
@to_dataframe
class DataFrameOut(to_schema(DataFrameIn)):
Age: Series[int] = Field()
class Config:
strict = True
Validation
@check_annotations
def func_ok(df: DataFrameIn) -> DataFrameOut:
return df.assign(Age=2)
@check_annotations
def func_err(df: DataFrameIn) -> DataFrameOut:
return df.assign(Age="")
@check_annotations
def func_err_output_tuple(df: DataFrameIn) -> Tuple[DataFrameOut]:
return (df.assign(Age=""),)
df_ok = pd.DataFrame({"Name": ["1"]})
df_ng = pd.DataFrame({"Name": [1]})
func_ok(df_ok) # OK
try:
func_ok(df_ng) # Input error
except SchemaError as e:
print(e)
try:
func_err(df_ok) # Output error
except SchemaError as e:
print(e)
try:
func_err_output_tuple(df_ok) # Output error
except SchemaError as e:
print(e)
Type coerce
df1 = pd.read_csv(StringIO("Name\n1"))
try:
func_ok(df1) # Input error
except SchemaError as e:
print(e)
df2 = pd.read_csv(StringIO("Name\n1"), dtype=dtype(DataFrameIn))
func_ok(df2) # OK
df3 = df_ng.astype(dtype(DataFrameIn))
func_ok(df3) # OK
Metadata
Release files for pandera-tool 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pandera_tool-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / pandera_tool-0.1.0-py3-none-any.whl
| Download URL | pandera_tool-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
084fe0c65cc7558ef82c5fd9a70c1398ad9572711dee356c6e9a300f74e65313
|
|
BLAKE2b-256 checksum How to use checksums |
0cc4eb2decea05cfb58dbe464481422ef484bb6db3a04cd67acc42331757ec0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.2 Darwin/21.6.0
|
Security for pandera-tool 0.1.0
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.