SciRuby / daru

Data Analysis in RUby
BSD 2-Clause "Simplified" License
1.04k stars 139 forks source link

group_by fails on 1 row size DataFrame #459

Closed vanitu closed 6 years ago

vanitu commented 6 years ago

method fails when DataFrame size == 1

df=Daru::DataFrame.new([{a: :a, b: 1}], oder: [:name], index: [:test])

=> #<Daru::DataFrame(1x2)>
         a    b
 test    a    1

df.group_by(:a)
ArgumentError: Can't create DataFrame from [1]
vanitu commented 6 years ago

Issue is that method "access_row_tuples_by_indexs" returns 2 types of values

Example:


df=Daru::DataFrame.new([{a: 1, b: 2},{a:3,b:4}], index: [:test,:test2])

 => #<Daru::DataFrame(2x2)>
           a     b
  test     1     2
 test2     3     4

df2.access_row_tuples_by_indexs(:test)
 => [1, 2] #Array of values
df2.access_row_tuples_by_indexs(:test,:test2)
 => [[1, 2], [3, 4]] #Array of arrays

problem is that populate_row_for(positions) for Numeric position is not wrapped in array

def access_row_tuples_by_indexs *indexes
      positions = @index.pos(*indexes)

      return populate_row_for(positions) if positions.is_a? Numeric

      res = []
      new_rows = @data.map { |vec| vec[*indexes] }
      indexes.each do |index|
        tuples = []
        new_rows.map { |row| tuples += [row[index]] }
        res << tuples
      end
      res
    end
vanitu commented 6 years ago

I found that this error was fixed, but Daru gem is not released and still linked to 7month old version. When Daru release planned and what is the flow for that?

zverok commented 6 years ago

I found that this error was fixed, but Daru gem is not released and still linked to 7month old version. When Daru release planned and what is the flow for that?

In a day or two :)