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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0042f4d1a04594f39083ec719a3fd5892a21505fbe9bb1029d0c22e01c433d4d |
|
MD5 | c0836b61cee0dacf0a8db4a9f88ad74c |
|
BLAKE2b-256 | 918a8de3a4385a2616ac316cbacfa16e36367e7d2929911f71a225a490eab921 |
Hashes for strictly_typed_pandas-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b78f93269f550a1d86e937790dfe38f3948d135482e56cd492a46e048f19cfe7 |
|
MD5 | 026b7533b3dfc4f342243461084b000a |
|
BLAKE2b-256 | f7481a99d72c433568e7fbd7f68296e2a19ed34419b534185094236ba0bce6ed |