ankane / ruby-polars

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

Docs: Add example of using Enum datatype #85

Closed DeflateAwning closed 1 month ago

DeflateAwning commented 1 month ago

Docs page: https://www.rubydoc.info/gems/polars-df/Polars/Enum

It would be awesome if you added an example of how to use the Enum type!

Thanks!

ankane commented 1 month ago

Hi @DeflateAwning, check out https://docs.pola.rs/user-guide/expressions/categorical-data-and-enums/.

DeflateAwning commented 1 month ago

For sure! It could be that I'm way more experienced in Python, and don't have an intuitive understanding of what equivalent code looks like in Ruby, but I couldn't figure it out (hence opening this issue).

The following attempts didn't seem to work for me:

Polars::Enum(['val1', 'val2'])
Polars.Enum(['val1', 'val2'])
Polars::Enum.initialize(['val1', 'val2'])

Can you offer advice? I maintain that a tiny example of the syntax in the docs would be valuable.

ankane commented 1 month ago

The way to initialize a class in Ruby is with new.

Polars::Enum.new(["val1", "val2"])
DeflateAwning commented 1 month ago

Would you mind adding that as a one-sentence example in the docs?

It's an example of where the Ruby syntax differs from the Python syntax, and so I strongly believe it should be documented.