pola-rs / pyo3-polars

Plugins/extension for Polars
MIT License
232 stars 38 forks source link

Allow to set expression output type based on kwargs #52

Open borchero opened 8 months ago

borchero commented 8 months ago

I'm currently experimenting with the expression plugins and, in particular, I'd like to implement a function

to_dummies(categories: list[str])

that turns a single column into a struct with the fields provided in categories.

Unfortunately, one cannot currently define the output_type of a polars_expr based on the kwargs passed to the function but only based on the input dtypes.

Rust macros are not my strong suite, unfortunately, so I can't really judge if this is feasible at all :eyes:

Shoeboxam commented 4 months ago

I had the same need, and noticed an undocumented function output_type_func_with_kwargs that you will also find useful.

borchero commented 4 months ago

Nice, thanks for the hint @Shoeboxam! Seems like this could, indeed, fix the issue, I'll investigate ;) in any case, it was only introduced in #62, i.e. after this issue 😜