A Polars plugin for vertical operations on columns 1D arrays or lists of equal length - aggregate across rows instead of within lists.
🚧 Under Development
Initialized from
https://github.com/MarcoGorelli/cookiecutter-polars-plugins:
thanks to Marco Gorelli for writing the excellent Polars Plugins Tutorial.
uv add polars-vec-ops>>> import polars as pl
>>> import polars_vec_ops # registers the `vec` namespace on columns/expressions
>>> df = pl.DataFrame({"a": [[1, 2, 3], [4, 5, 6]]})
>>> df.select(pl.col("a").vec.sum())
shape: (1, 1)
┌───────────┐
│ a │
│ --- │
│ list[i64] │
╞═══════════╡
│ [5, 7, 9] │
└───────────┘
# alternatively, use functions on column names (with IDE hints and proper type checking):
>>> import polars_vec_ops as vec
>>> df.select(vec.sum("a"))
shape: (1, 1)
┌───────────┐
│ a │
│ --- │
│ list[i64] │
╞═══════════╡
│ [5, 7, 9] │
└───────────┘All operations work vertically (across rows) on List or Array columns:
sum()- Sum elements at each positionmean()/avg()- Calculate mean at each positionmin()/max()- Find min/max at each positiondiff()- Calculate row-to-row differences
- Works with both List and Array dtypes
- Handles null rows and null elements
- Type preservation where possible (Int64, Float64, etc.)
- Fast Rust implementation via PyO3
# Install dev dependencies
uv sync
# Rebuild after modifying Rust code
maturin develop --release
# Run tests
pytestMIT