Skip to main content

Type hinting for pandas DataFrame

Project description

datahints

Validate pandas dataframes using type information. Enables IDE autocompletion and refactoring of column names as well as explicitly documenting expected columns and their data types.

All dataframes are treated as standard pandas dataframes, no instancing of the subclasses is required.

Installation

pip install datahints

Example

import pandas as pd
import numpy as np
from datahints import DataFrame, Series
from typing import Optional, Union

class MyDataFrame(DataFrame):
    col1: Series[int]
    col2: Series[Union[int, float]]
    col3: Optional[Series[np.float64]]

# validate any dataframe
df = pd.DataFrame({"col1": [1, 2], "col2": [3.0, 4.0]})
MyDataFrame.validate(df)

# validate and annotate type for IDE support
df = MyDataFrame.validate(df)

# use statically named columns 
df[MyDataFrame.col3] = [5.0, 6.0]

# constructor simply returns a dataframe instance
df = MyDataFrame({MyDataFrame.col1: [1, 2], MyDataFrame.col2: [3.0, 4.0]})
MyDataFrame.validate(df)

# create and validate directly
df = MyDataFrame.create({
    MyDataFrame.col1: [1, 2],
    MyDataFrame.col2: [3.0, 4.0]
})

# infer column names automatically (if all columns are present)
df = MyDataFrame.create([
    (1, 3.0, 5.0),
    (2, 4.0, 6.0)
])

Type inference

Native types are automatically assumed to represent the following numpy equivalents:

type dtype
str np.str_, np.object_
int np.int32, np.int64
float np.float32, np.float64
bool np.bool_
date, datetime "datetime64[ns]"

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

datahints-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

datahints-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file datahints-0.1.1.tar.gz.

File metadata

  • Download URL: datahints-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Darwin/20.6.0

File hashes

Hashes for datahints-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cdd92b4ae51321313e32279f3d0f073fc43999213b17460f01cfcdbffd2acc8c
MD5 283ab450bd4da62e14dbd1df308a07d0
BLAKE2b-256 f960ee50afced06ba7ec93ee09964b49178203bb667f631a913588d460be3f80

See more details on using hashes here.

File details

Details for the file datahints-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: datahints-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Darwin/20.6.0

File hashes

Hashes for datahints-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8026d602d533b37ffb0dce1ad13d2dd148d392fe8d53c837ff0d55a4fa6f9b38
MD5 4c635ad8c969e81cb6ff6fb89b7cf256
BLAKE2b-256 66c18bea2321a41410b617d8224331abd5a827ef624d53013e4ceae1c483e08c

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