Skip to main content

Named Data Frames

Project description

namedframes

Basic type annotation support for Pandas and Spark data frames. The goal is to provide a convenient way to specify a name-to-type mapping. The assurance that the columns conform to the types is left to the user, i.e. this provides named data frames, not typed data frames.

Installation

pip install namedframes

Usage

import pandas as pd
from namedframes import PandasNamedFrame

class InputDF(PandasNamedFrame):
    x: float

class OutputDF(InputDF):
    blah: bool


def transform(input_data: InputDF) -> OutputDF:
    return OutputDF(input_data.assign(blah = True))

input_df = InputDF(pd.DataFrame({"x": [1.1, 2.2]}))

output = transform(input_df)

isinstance(input_df, InputDF)
True

isinstance(output, OutputDF)
True

If a column is missing, a validation error occurs,

OutputDF(input_df)

ValueError: missing columns: [('blah', <class 'bool'>)]

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

namedframes-0.1.2.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

namedframes-0.1.2-py2.py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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