A tool for generating dataclass type files for pandas DataFrame rows
Project description
df_types
Python tool for generating dataclass type files for pandas DataFrame rows.
Installation
pip install df-types
Usage
from df_types import DFTypes
import pandas as pd
df = pd.read_csv("dev.csv")
dft = DFTypes(df)
dft.write_types() # creates typed_df.py in the current directory
# see df_types.config.DFTypesConfig for options
# then use the types file as a module
from typed_df import convert, iter_dataclasses
df = convert(df)
for dc in iter_dataclasses(df):
... # do something with dc
In the above example, convert and iter_dataclasses are generated from typed_df.py. convert is a function that takes a DataFrame and normalizes the column names, replacing NaN values with None (by default).
iter_dataclasses is a generator that takes a DataFrame and yields a dataclass for each row.
Features
Currently, the following features are supported:
- Literal types for primitive types (e.g.
Literal["some_type", "other_type"]) - Union types (e.g.
int | float) - Optional types (e.g.
int | None) - Imported/custom types (e.g.
pd.Timestamp, user defined types)
In the future, I'd like to add support for typed containers (e.g. Dict[str, int], List[int]).
License
MIT
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 df-types-0.0.1.tar.gz.
File metadata
- Download URL: df-types-0.0.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30a59cff11ac194b514dc4a8c3dbbbe2e047233b733284fc79bc5c9aa569cc25
|
|
| MD5 |
6e2a2fb941166b697848df93ca68fd1e
|
|
| BLAKE2b-256 |
eaaeb7142d7128315c1df16a9bd18391f4cd4374e27d04fc6d0cc5ede3346e9d
|
File details
Details for the file df_types-0.0.1-py3-none-any.whl.
File metadata
- Download URL: df_types-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e52c70af6e5bd890b5e0e4d19edea30a5d9a434afe2b0e0bd669cab224e136d3
|
|
| MD5 |
b4ac51067dc77e4424e52a8b6ff21ee3
|
|
| BLAKE2b-256 |
b30249477d237e09b73b3da8cd01f1cf0f040f0761e9da7c98f6e7c012a7ef3b
|