Skip to main content

Bamboo

Current version: "0.0.2"

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

Release files for bamboo-pandas 0.0.2

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

Source distribution (sdist)

Source distribution for bamboo-pandas 0.0.2
File Size Uploaded
bamboo_pandas-0.0.2.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bamboo-pandas 0.0.2
File Interpreter ABI Platform
bamboo_pandas-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.2 kB

Release files / bamboo_pandas-0.0.2.tar.gz

Download URL bamboo_pandas-0.0.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
28d99e6460946feef81f74e04db03725d4946d09086aba4e590f15bcdc9b2184
BLAKE2b-256 checksum
How to use checksums
bdced5312c0c0529192582ad6ffc33c8c035b1e456c3848236c97c55e63ad7ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.11 Linux/5.15.153.1-microsoft-standard-WSL2

Release files / bamboo_pandas-0.0.2-py3-none-any.whl

Download URL bamboo_pandas-0.0.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2391fdd4d1e29e819d0b59e074872b5b27f4e638632304bad08273ccc459905b
BLAKE2b-256 checksum
How to use checksums
3dbceb4b526cad7c40d6c9ac5a8e816dc12b4a1fb2cb16e5e1523a0bf488612f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.11 Linux/5.15.153.1-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

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