ankane/ruby-polars

a mistake when construct df from hash

kkzhang opened this issue · 3 comments

Polars::DataFrame.new({
  a: [1, 2, 3],
})

above code is expected to be resulted an 3x1 dimensions dataframe, but actually it is a 1x1.

Another way works:

Polars::DataFrame.new [
            Polars::Series.new("close", [4,5,6,7])
]

Hi @kkzhang, I'm not sure how to reproduce. That code works as expected.

shape: (3, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 1   │
│ 2   │
│ 3   │
└─────┘
irb(main):001> require 'polars'
=> true
irb(main):002* Polars::DataFrame.new [
irb(main):003*   Polars::Series.new("close", [6,5,6,7,4,2,2])
irb(main):004> ]
=> 
shape: (7, 1)
┌───────┐
│ close │
│ ---   │
│ i64   │
╞═══════╡
│ 6     │
│ 5     │
│ 6     │
│ 7     │
│ 4     │
│ 2     │
│ 2     │
└───────┘
irb(main):005* Polars::DataFrame.new [
irb(main):006*   "close": [6,5,6,7,4,2,2]
irb(main):007> ]
=> 
shape: (1, 1)
┌─────────────┐
│ close       │
│ ---         │
│ list[i64]   │
╞═════════════╡
│ [6, 5, … 2] │
└─────────────┘

Am i doing it wrong?

irb(main):003> Polars::VERSION
=> "0.9.0"

ruby version: 3.2.3 / 3.3.0

You'll want to use a hash in the last example instead of an array containing a single hash if you're trying to produce the same result.