Open stevenlis opened 1 year ago
.arr.get
returns null
instead of raising, which may be another option:
>>> df.groupby("group", maintain_order=True).agg(pl.col("value").list().arr.get(2))
shape: (2, 2)
┌───────┬───────┐
│ group ┆ value │
│ --- ┆ --- │
│ str ┆ i64 │
╞═══════╪═══════╡
│ one ┆ 2 │
│ two ┆ null │
└───────┴───────┘
I would love for take to have this as a flag though... I think its a pretty reasonable and common use case! take
syntactically is more canonical for operating on columns instead of treating it as an array imo.
Also seems that list.take
has this flag but not take
? https://pola-rs.github.io/polars/py-polars/html/reference/expressions/api/polars.Expr.list.take.html
Problem description
Sometimes you may have groups with different numbers of rows. It would be nice if
polars.Expr.take
could just return anull
whenindex out of bounds
.For now: