Typed Wrappers over Pandas DataFrames with schema validation
Project description
🐍 typedframe
Typed wrappers over pandas DataFrames with schema validation.
TypedDataFrame
is a lightweight wrapper over pandas.DataFrame
that provides runtime schema validation and can be used to establish strong data contracts between interfaces in your Python code.
>>> from typedframe import TypedDataFrame, DATE_TIME_DTYPE
>>> class MyTable(TypedDataFrame):
... schema = {
... "col1": object, # str
... "col2": np.int32,
... "col3": ('foo', 'bar')
... }
... optional = {
... "col4": bool,
"col5": DATE_TIME_DTYPE
... }
>>> df = pd.DataFrame({"col1": ['foo'], "col2": np.array([1], dtype=np.int32), "col3": ['bar']})
>>> df.col3 = pd.Categorical(df.col3, categories=('foo', 'bar'), ordered=True)
>>> print(MyTable(df).df)
Supported Data Types
- Integers:
np.int16
,np.int32
,np.int64
, etc. - Floats:
np.float16
,np.float32
,np.float64
, etc. - Boolean:
bool
- String:
STRING_DTYPE
- Python object:
object
- Categorical:
category
- Date, Datetime:
DATE_TIME_DTYPE
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
typedframe-0.5.2.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for typedframe-0.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71f235943ca7a69e284ec332782e5aac4b8d6ef4ca389934f815de481c3fd4ac |
|
MD5 | 4a3e9d2e63c1df4d5d0ad2a10c6e19b8 |
|
BLAKE2b-256 | 200ff8304fdaf9921d1acc564fe53a2d7854809a04b625c138abb5111b06b84f |