Open cmdlineluser opened 1 month ago
Did it used to work in an older version?
It doesn't seem so.
Just randomly tried a few versions back to 0.20.10
and it panics there also.
The reason .agg(aggs)
works is this branch:
https://github.com/pola-rs/polars/blob/29cdb17deadf725c8b98bf2bacfde434ba156111/py-polars/polars/_utils/parse/expr.py#L122-L124
which handles the Iterable[IntoExpr]
part of the IntoExpr | Iterable[IntoExpr]
type.
.agg("index", aggs)
does not satisfy this condition (there are 2 inputs), and [pl.col("y")]
is converted into an expression representing a literal (list of objects, length 1) value here:
https://github.com/pola-rs/polars/blob/29cdb17deadf725c8b98bf2bacfde434ba156111/py-polars/polars/functions/lit.py#L143-L150
Eventually in Rust this causes a panic because the dtype of the list (being a pl.col()
object) is not supported.
I suggest adopting the *more_exprs
argument style for agg()
(and with_columns()
and other functions with similar arguments) to remove the ambiguity between literal lists and iterables of IntoExpr
s:
https://github.com/pola-rs/polars/blob/54218e7e35e3defd4b0801e820c56eea6b91e525/py-polars/polars/expr/expr.py#L3377-L3383
Checks
Reproducible example
Log output
No response
Issue description
There is a similar issue for
with_columns
https://github.com/pola-rs/polars/issues/17413I originally has a list of agg exprs but was modifying a querying to add an index column and hit this.
The list can be unpacked as a workaround.
.agg("index", *aggs)
Expected behavior
No panic.
Installed versions