Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_index fails if data_frame size is zero #530

Open
dipanm opened this issue Apr 6, 2020 · 0 comments
Open

set_index fails if data_frame size is zero #530

dipanm opened this issue Apr 6, 2020 · 0 comments

Comments

@dipanm
Copy link

dipanm commented Apr 6, 2020

If we create a row data frame with only 1 row, but it has multi-index it works

> df1 = Daru::DataFrame.new( { 'Beer' => ['Kingfisher'] , 'Gallons sold' => [500 ] }, :index  => [[ 'Asia', 'india'] ] )
 => #<Daru::DataFrame(1x2)>
                             Beer Gallons so
       Asia      india Kingfisher        500 

If we have a data frame with only 1 row, and if we try to raise a single index it also works.

> df2 = Daru::DataFrame.new( { 'Beer' => ['Kingfisher'] , 'Gallons sold' => [500 ], 'Country' => [ 'india' ], 'Continent' => ['Asia'] })
 => #<Daru::DataFrame(1x4)>
                  Beer Gallons so    Country  Continent
          0 Kingfisher        500      india       Asia 
 > df2.set_index('Continent')
 => #<Daru::DataFrame(1x3)>
                  Beer Gallons so    Country
       Asia Kingfisher        500      india 

However, if we try to set a multi-index when the data frame size is 1, it fails deterministically

> df3 = Daru::DataFrame.new( { 'Beer' => ['Kingfisher'] , 'Gallons sold' => [500 ], 'Country' => [ 'india' ], 'Continent' => ['Asia'] })
 => #<Daru::DataFrame(1x4)>
                  Beer Gallons so    Country  Continent
          0 Kingfisher        500      india       Asia 

> df3.set_index( ['Continent', 'Country'] )
Traceback (most recent call last):
        5: from /Users/Dipan/.rvm/rubies/ruby-2.6.3/bin/irb:23:in `<main>'
        4: from /Users/Dipan/.rvm/rubies/ruby-2.6.3/bin/irb:23:in `load'
        3: from /Users/Dipan/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        2: from (irb):11
        1: from /Users/Dipan/.rvm/gems/ruby-2.6.3/gems/daru-0.2.2/lib/daru/dataframe.rb:1577:in `set_index'

Trying to add indexes one by one also fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants