`bamboo` is Python package that attempts to add more structure and validation to pandas data transformations.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bamboo_pandas-0.0.2.tar.gz.
File metadata
- Download URL: bamboo_pandas-0.0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28d99e6460946feef81f74e04db03725d4946d09086aba4e590f15bcdc9b2184
|
|
| MD5 |
00d8d3474fc8491f95f5abb08b4429fd
|
|
| BLAKE2b-256 |
bdced5312c0c0529192582ad6ffc33c8c035b1e456c3848236c97c55e63ad7ed
|
File details
Details for the file bamboo_pandas-0.0.2-py3-none-any.whl.
File metadata
- Download URL: bamboo_pandas-0.0.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2391fdd4d1e29e819d0b59e074872b5b27f4e638632304bad08273ccc459905b
|
|
| MD5 |
4c247429eba11ff01b8258d7239c6492
|
|
| BLAKE2b-256 |
3dbceb4b526cad7c40d6c9ac5a8e816dc12b4a1fb2cb16e5e1523a0bf488612f
|