Static type checking of pandas DataFrames
Project description
I love Pandas! But in production code I’m always a bit wary when I see:
import pandas as pd
def foo(df: pd.DataFrame) -> pd.DataFrame:
# do stuff
return df
Because… How do I know which columns are supposed to be in df?
Using strictly_typed_pandas, we can be more explicit about what these data should look like.
from strictly_typed_pandas import DataSet
class Schema:
id: int
name: str
def foo(df: DataSet[Schema]) -> DataSet[Schema]:
# do stuff
return df
- Where DataSet:
is a subclass of pd.DataFrame and hence has the same functionality as DataFrame.
validates whether the data adheres to the provided schema upon its initialization.
is immutable, so its schema cannot be changed using inplace modifications.
- The DataSet[Schema] annotations are compatible with:
mypy for type checking during linting-time (i.e. while you write your code).
typeguard for type checking during run-time (i.e. while you run your unit tests).
- To get the most out of strictly_typed_pandas, be sure to:
set up mypy in your IDE.
run your unit tests with pytest –typeguard-packages=foo.bar (where foo.bar is your package name).
Installation
pip install strictly-typed-pandas
Documentation
For example notebooks and API documentation, please see our ReadTheDocs.
FAQ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for strictly_typed_pandas-0.1.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fed873d77f048375edf41a71eb3a7fa7f5c26faee13db42968d39c40d81499e |
|
MD5 | 513e4e4631c248ab4b89c5caf2c5df7e |
|
BLAKE2b-256 | 53d1510f11e76e2e4753b26040eef52e0d99d9a711a8e35de2776311b5899d2f |
Hashes for strictly_typed_pandas-0.1.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9076bb6eea7a223ee7cf889860dacb3d3688437b62e4960fce83300c38ad9ad |
|
MD5 | e9b43665792305d9aba7ba530d2ca1cb |
|
BLAKE2b-256 | 6b8acaddbd1116f2b524695e99917f688b4df98d2f2cbaddb96e0c7a665d3991 |