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
>>> class MyTable(TypedDataFrame):
... schema = {
... "col1": object, # str
... "col2": np.int32,
... "col3": 'category'
... }
... optional = {
... "col4": bool,
"col5": np.dtype('datetime64[ns]')
... }
>>> df = pd.DataFrame({"col1": ['foo'], "col2": np.array([1], dtype=np.int32), "col3": ['bar']})
>>> df.col3 = df.col3.astype("category")
>>> 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.2.1.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for typedframe-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2591c564ded388185fa57345235c3c19f011b87654451293c6534623697f82a |
|
MD5 | cfa871f0fc15e3b4680ea0b2e9bdc665 |
|
BLAKE2b-256 | 27212c70d695f378684aa56792e69d7f8eb5634f615d77c0bfffffb7a6b424ce |