Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

df-types-0.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

df_types-0.0.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

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

Hashes for df-types-0.0.1.tar.gz
Algorithm Hash digest
SHA256 30a59cff11ac194b514dc4a8c3dbbbe2e047233b733284fc79bc5c9aa569cc25
MD5 6e2a2fb941166b697848df93ca68fd1e
BLAKE2b-256 eaaeb7142d7128315c1df16a9bd18391f4cd4374e27d04fc6d0cc5ede3346e9d

See more details on using hashes here.

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

Hashes for df_types-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e52c70af6e5bd890b5e0e4d19edea30a5d9a434afe2b0e0bd669cab224e136d3
MD5 b4ac51067dc77e4424e52a8b6ff21ee3
BLAKE2b-256 b30249477d237e09b73b3da8cd01f1cf0f040f0761e9da7c98f6e7c012a7ef3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page