eval_aligned¶
- pydiverse.transform.eval_aligned( ) EvalAligned[source]¶
Allows to evaluate a column expression containing columns from different tables and to use polars / pandas Series in column expressions.
- Parameters:
val – The expression or polars / pandas Series to be aligned.
with – The table or column to align with.
Examples
Usage of a polars Series in a column expressions (the same works for pandas Series):
>>> import polars as pl >>> t = pdt.Table( ... { ... "a": [1, 2, 3, 4], ... "b": [2, 5, 16, 3], ... }, ... name="t", ... ) >>> s = pl.Series([9, 5, 4, 1]) >>> t >> mutate(c=eval_aligned(t.a + s)) >> show() Table `t` (backend: polars) shape: (4, 3) ┌─────┬─────┬─────┐ │ a ┆ b ┆ c │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ i64 │ ╞═════╪═════╪═════╡ │ 1 ┆ 2 ┆ 10 │ │ 2 ┆ 5 ┆ 7 │ │ 3 ┆ 16 ┆ 7 │ │ 4 ┆ 3 ┆ 5 │ └─────┴─────┴─────┘
Expression containing columns from different tables:
>>> t1 = pdt.Table({"a": [1, 2, 3, 4]}, name="t1") >>> t2 = pdt.Table({"a": [5, 3, 1, 3]}, name="t2") >>> t1 >> mutate(c=eval_aligned(t1.a + t2.a, with_=t1)) >> show() Table `t1` (backend: polars) shape: (4, 2) ┌─────┬─────┐ │ a ┆ c │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞═════╪═════╡ │ 1 ┆ 6 │ │ 2 ┆ 5 │ │ 3 ┆ 4 │ │ 4 ┆ 7 │ └─────┴─────┘