ankane/ruby-polars

Add `Expr.map_elements(...)` functionality

DeflateAwning opened this issue · 5 comments

Python and Rust Polars both prefer map_elements to apply, and have a deprecation warning.

At the very least, I think that .map_elements should work and should be in the doc.

Upon further inspection, I'm getting errors like NoMethodError (undefined method 'apply' for col("date_min"):Polars::Expr) while trying:

                  df.with_columns(
                    date: Polars.col('date_min').apply {|date_min| Polars.date_range(date_min, date_max, "1mo")}
                  )

Looking at the docs, I see DataFrame.apply and Series.apply, but no XxxExpr.apply. I think maybe those function mappings/implementations were missed entirely. Wondering if they could be added?

Hi @DeflateAwning, Series already has map_elements, and I aliased DataFrame#apply to map_rows in 6b8c9b4. I haven't been able to get Expr#map_elements/Expr#apply to work without crashing, but someone is welcome to submit a PR if they're able to.

Darn, okay. That's a pretty big limitation for now; I guess the workaround for that is to iterate through the rows and then reconstruct a dataframe afterwards.