aligned

pydiverse.transform.aligned(fn=None, *, with_: str | None = None)[source]

Decorator that automatically applies eval_aligned to the return value of a function.

Parameters:

with – The table or column to align with.

Examples

>>> @aligned(with_="col")
... def reverse_col(col: pdt.Col) -> pdt.ColExpr:
...     return col.export(Polars).reverse()
...
>>> t = pdt.Table(
...     {
...         "a": [1, 2, 3, 4],
...         "b": [2, 5, 16, 3],
...     },
...     name="t",
... )
>>> t >> mutate(r=reverse_col(t.a)) >> show()
Table `t` (backend: polars)
shape: (4, 3)
┌─────┬─────┬─────┐
│ a   ┆ b   ┆ r   │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╡
│ 1   ┆ 2   ┆ 4   │
│ 2   ┆ 5   ┆ 3   │
│ 3   ┆ 16  ┆ 2   │
│ 4   ┆ 3   ┆ 1   │
└─────┴─────┴─────┘