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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strictly_typed_pandas-0.3.6.tar.gz.
File metadata
- Download URL: strictly_typed_pandas-0.3.6.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a80c71e140503309b09e500ac9051704cd12d74dd39671ff11063731f949d68
|
|
| MD5 |
92bc530c61173820bc318ab4177e9ed4
|
|
| BLAKE2b-256 |
e77d5e2fb1ccca0c7cf82112e16ccc7b5677062065cdbd103c891d5bebe2c530
|
File details
Details for the file strictly_typed_pandas-0.3.6-py3-none-any.whl.
File metadata
- Download URL: strictly_typed_pandas-0.3.6-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2bd5e398331405b1322fb636148bf0444fe69cbbcfd5900302015774fad15ef
|
|
| MD5 |
292153cca601a0573e63a91851ca7235
|
|
| BLAKE2b-256 |
b730b6c499864261518ac79a8891202091d010894924296fa305c44d13a6bc28
|