ankane / ruby-polars

Blazingly fast DataFrames for Ruby
MIT License
836 stars 30 forks source link

Filter with Date #84

Closed topofocus closed 2 hours ago

topofocus commented 2 hours ago

After changing the date-format from string to native date-objects, Polars-filtering constantly produces the error cant't convert Date to Float (TypeError)

# Create DataFrame
df = Polars::DataFrame.new({
    "datum" => [Date.parse("2023-08-31"), Date.parse("2023-09-30"), Date.parse("2023-10-01")],
    "value" => [10, 20, 30]
})
# Define the date range
start_date = Date.parse("2023-10-01")
end_date = Date.parse("2023-12-31")

df.filter( Polars.col("datum") >= start_date )

/usr/share/rvm/gems/ruby-3.2.0/gems/polars-df-0.3.1-x86_64-linux/lib/polars/lazy_functions.rb:297:in lit: can't convert Date into Float (TypeError) Utils.wrap_expr(RbExpr.lit(value))

also

filtered_df = df.filter( Polars.col("datum").is_between(start_date, end_date))

fails

ArgumentError: did not expect value '2023-10-01' of type Date, maybe disambiguate with Polars.lit or Polars.col.

Is there a walkaround?

ankane commented 2 hours ago

Hi @topofocus, it looks like you're on an older version of the gem. Both work fine with the latest version.