ankane / ruby-polars

Blazingly fast DataFrames for Ruby
Other
858 stars 34 forks source link

Error caused when filter receives 7.to_s instead of '7' #88

Closed gsinclair closed 3 weeks ago

gsinclair commented 3 weeks ago

Here is some code that triggers an error, when it seems pretty clear that it should not trigger an error.

require 'polars-df'

df = Polars::DataFrame.new([
  {code: '7A', desc: "happy"},
  {code: '8A', desc: "sad"},
  {code: '7C', desc: "in-between"}
])

# The following line will work.
puts df.filter(Polars.col('code').str.starts_with('7'))

# The following line will cause an exception:
#   invalid series dtype: expected `String`, got `binary` (Polars::Error)
puts df.filter(Polars.col('code').str.starts_with(7.to_s))

Here is the beginning of my gem env. Also: I am using polars-df (0.14.0 arm64-darwin) via Rubygems.

RubyGems Environment:
  - RUBYGEMS VERSION: 3.5.18
  - RUBY VERSION: 3.3.5 (2024-09-03 patchlevel 100) [arm64-darwin23]
  - INSTALLATION DIRECTORY: /opt/homebrew/lib/ruby/gems/3.3.0
  - USER INSTALLATION DIRECTORY: /Users/gsinclair/.gem/ruby/3.3.0
  - RUBY EXECUTABLE: /opt/homebrew/opt/ruby/bin/ruby
  - GIT EXECUTABLE: /opt/homebrew/bin/git
  - EXECUTABLE DIRECTORY: /opt/homebrew/lib/ruby/gems/3.3.0/bin
  - SPEC CACHE DIRECTORY: /Users/gsinclair/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /opt/homebrew/Cellar/ruby/3.3.5/etc
ankane commented 3 weeks ago

Hi @gsinclair, see #77.

gsinclair commented 2 weeks ago

Thank you. Is there any chance of giving a clearer error message when this happens? It's weird to pass a string to a method and get an error message saying "expecting String".