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 likebeartype(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 withvalidate().tqdm_swifter.py— shows compatibility withtqdmandswifter.beartyped_columns.py— example usingbeartypefor 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)
| File | Size | Uploaded | |
|---|---|---|---|
| bamboo_pandas-0.0.2.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|