ankane/ruby-polars

Sequel gem support

DanFCo opened this issue ยท 7 comments

Right now it looks like it's only supporting ActiveRecord for an ORM.

Are there any plans on supporting the Sequel gem for ruby codebases who use Sequel over ActiveRecord?

Right now we're using a work around to convert our database results into json and having the DataFrame read it in on initialization. It's not the prettiest code to write but it gets the job done ๐Ÿ˜Ž .

Hi @DanFCo, just looked into adding this, but I'm not sure it's needed. It should be possible to pass results directly to the data frame constructor.

Polars::DataFrame.new(DB[:users].to_a)
# or
Polars::DataFrame.new(DB["SELECT * FROM users"].to_a)

hey @ankane thanks so much for the quick response!

Unfortunately I get an unsupported object type runtime error:

ruby-dev >> users = Polars::DataFrame.new(DB[:users].to_a)
# DB: (0.144231s) SELECT * FROM "users"
	
# RuntimeError: object type not supported {}
# from /bundle/ruby/3.2.0/gems/polars-df-0.7.0/lib/polars/data_frame.rb:5044:in `read_hashes'



ruby-dev >> Polars::DataFrame.new(DB["SELECT * FROM users"].to_a)
# DB: (0.040828s) SELECT * FROM users
	
# RuntimeError: object type not supported {}
# from /bundle/ruby/3.2.0/gems/polars-df-0.7.0/lib/polars/data_frame.rb:5044:in `read_hashes'

sample of the data shape that DB[...].to_a returns in both examples above:

ruby-dev >> DB["SELECT * FROM `users"].to_a
# DB: (0.018385s) SELECT * FROM users
	
=> [
        {
          :id=>2,
          :email=>"person1@email.com",
         },
         {
          :id=>3,
          :email=>"person2@email.com",
         },
  ]

Would love to help out in any way that I can!

I'd try to narrow down the value that's producing that error (since it doesn't happen with the array above).

Hey @ankane I narrowed it down and figured out the issue!

i have a column in the users table :row that points to a json. The column in default state is the empty curly brackets {}

if i convert it to read as json it will create the data frame with the column type as Struct. It's why our current work around is doing the trick ๐Ÿ˜…

Thanks @DanFCo, will try to fix when I have a chance.

Hi @DanFCo, I'm having trouble reproducing the error. Can you create a minimal reproducible example when you have a chance?

so sorry for the delay in response here! I was able to determine the issue was on our end in how we shaped the object. Thanks again for your help and attention on this.

Cheers!