Skip to main content

`bamboo` is Python package that attempts to add more structure and validation to pandas data transformations.

Project description

Bamboo

Current version: "0.0.1"

Bamboo is a small library that adds structure and validation to pandas DataFrame row-transformations. It provides a lightweight way to declare the expected input and output shapes for a row-wise transformation using simple Bamboo data objects, and a decorator that converts between pd.Series rows and your typed objects while validating inputs and outputs.

Why use bamboo

  • Safer transforms: validate that each row can be converted into the declared input type and the transformation returns the expected output type.
  • Documented data contracts: row types live next to your transform code, making the expected inputs/outputs explicit and easy to read.
  • Plays nicely with tooling: works with tqdm, swifter, and runtime type checkers like beartype (see examples).

Quick example

This example demonstrates the default, type-hinted usage with @bamboo_transform.

from dataclasses import dataclass
import pandas as pd

from bamboo import BambooObject, bamboo_transform


@dataclass
class Row(BambooObject):
    a: int
    b: int


@dataclass
class Out(Row):
    pass


@bamboo_transform
def add_and_mul(row: Row) -> Out:
    return Out(a=row.a + 1, b=row.b * 2)


df = pd.DataFrame({"a": [1, 2, 3], "b": [10, 20, 30]})
validate(df, Row)
print(df.apply(add_and_mul, axis=1))

More examples

See the examples folder for:

  • default_typed.py — inferred typed example (default use-case).
  • default_untyped.py — parameterized decorator for un-annotated functions.
  • vectorized_validate.py — write fast vectorized operations, then validate output with validate().
  • tqdm_swifter.py — shows compatibility with tqdm and swifter.
  • beartyped_columns.py — example using beartype for runtime type checking.

Patterns

Row-wise with @bamboo_transform: Use when you need per-row type validation as you transform. Good for smaller datasets or when type contracts are critical. Works with tqdm, but may be slower with swifter (only row-wise path).

Vectorized + validate: Write fast vectorized operations (using pandas, swifter, or NumPy) and call validate() on the result as a sanity check. Good for large datasets where raw speed matters; validation happens after the fast operation completes.

Running examples

Install dev dependencies:

poetry install

Run an individual example:

python examples/default_typed.py
python examples/vectorized_validate.py
python examples/tqdm_swifter.py
python examples/beartyped_columns.py

Development

Install dev dependencies:

poetry install

See the Makefile for common commands.

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

bamboo_pandas-0.0.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

bamboo_pandas-0.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file bamboo_pandas-0.0.1.tar.gz.

File metadata

  • Download URL: bamboo_pandas-0.0.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.12.11 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for bamboo_pandas-0.0.1.tar.gz
Algorithm Hash digest
SHA256 330c49f5ec42d1c36e8a3b16d30363fa24493e6091f54735bf8a7f0eb1760584
MD5 b3bc4b6a8813890c1af1480cbb32caae
BLAKE2b-256 48c5f9468d5cb10d5f709fa4b13f02ad52e975b64589a2fd4c701186c6859969

See more details on using hashes here.

File details

Details for the file bamboo_pandas-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: bamboo_pandas-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.12.11 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for bamboo_pandas-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8e420ba5f4d55d3bf070f04e4537bac672125098b51a9ae36098a50d7a61490
MD5 5bc0dff47f27270dc49777f20fbf3f85
BLAKE2b-256 867d4edc6e984b45906924796438b363ab58f9923156013978f5785a5c9d8d40

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