ankane/ruby-polars

Polars.min does not work with expressions

Closed this issue · 3 comments

When trying to compute the min across multiple columns, Polars raises an error when you attempt to pass an expression into Polars.min:

Polars::DataFrame.new([{a: 1, b: 2, c: 3}]).with_column(Polars.min(Polars.col("a")).alias("d"))
# Raises ...lib/polars/lazy_functions.rb:147:in `min': undefined method `_min_exprs' for Polars:Module (NoMethodError)

Hi @pstalcup, thanks for reporting. Since that path was never implemented in Ruby and no longer exists in Python, I've removed it in the commit above.

pl.DataFrame([{'a': 1, 'b': 2, 'c': 3}]).with_columns(pl.min(pl.col('a')).alias('d'))
# raises ValueError: could not convert value 'Unknown' as a Literal

You can use Polars.min("a") or Polars.min(["a", "b"]) instead.

That sounds good!
I am still getting the same error with this though:

 Polars::DataFrame.new([{a: 1, b: 2, c: 3}]).with_column(Polars.min(["a", "b"]).alias("d"))
 # lib/polars/lazy_functions.rb:147:in `min': undefined method `_min_exprs' for Polars:Module (NoMethodError)

        Utils.wrap_expr(_min_exprs(exprs))
                        ^^^^^^^^^^

It looks like Polars.min(["a", "b"]) won't work until the next release, but you can do:

df.with_column(Polars.min("a").alias("d")).with_column(Polars.min("b").alias("e"))