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 (<v3.0) 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 –stp-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
File details
Details for the file strictly_typed_pandas-0.3.5.tar.gz
.
File metadata
- Download URL: strictly_typed_pandas-0.3.5.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fc4a9dabf4c2fa9626de7cfe17967f6457458763b3bbbc8c832f88dc4161b08 |
|
MD5 | 95eb6b5a502911cdd7c28b7e2eef3f14 |
|
BLAKE2b-256 | 3b33bdbb81a51963119a4a96db29f36c4396636181287d96ab6130332ff32b09 |
File details
Details for the file strictly_typed_pandas-0.3.5-py3-none-any.whl
.
File metadata
- Download URL: strictly_typed_pandas-0.3.5-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60c12e714bbb37fcc8ba9abc97b175bf0754586dc9b3ae566ab589f4070dfae0 |
|
MD5 | e82091ad1d8057faa21f098e0baa2546 |
|
BLAKE2b-256 | 55a1cbf0c2e9c0646da6e6c02e97cc1d2227ab5839f4ad3893f0224d2e059304 |