Skip to main content

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

Pandas

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'>)]

Spark

namedframes includes an option for pyspark dataframes. Using it requires installation of pyspark. You can install this separately or with the [pyspark] flag to namedframes, i.e.,

pip install namedframes[pyspark]

Example usage:

import pandas as pd 
from pyspark.sql import SparkSession
from namedframes import SparkNamedFrame 

class InputDF(SparkNamedFrame): 
    x: float 

spark = SparkSession.builder.getOrCreate()
spark_df = spark.createDataFrame(pd.DataFrame({"x": [1.1, 2.2]}))                                                      
input_df = InputDF(spark_df)

Metadata

Release files for namedframes 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for namedframes 0.1.4
File Size Uploaded
namedframes-0.1.4.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for namedframes 0.1.4
File Interpreter ABI Platform
namedframes-0.1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 7.2 kB

Release files / namedframes-0.1.4.tar.gz

Download URL namedframes-0.1.4.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0042cb776af58735d4da2ec1e366f209a27b7676b36c92775827b30f646831fd
BLAKE2b-256 checksum
How to use checksums
17aa624d7f9d07e1e0344e4c97e9368549d919ed8f77db6b1f8adcb0f766cf91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5

Release files / namedframes-0.1.4-py2.py3-none-any.whl

Download URL namedframes-0.1.4-py2.py3-none-any.whl
Size 4.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
81608496813cedcf4c6da53414662e95ac8a00e5a50dd45e11f71defc548d58d
BLAKE2b-256 checksum
How to use checksums
2a66457381c917ad8336c4bde7f4d9adb31adbb5f341bfd231920b20969fd9cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page