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

Add_row with multi-index #415

Closed
info-rchitect opened this issue Sep 21, 2017 · 2 comments
Closed

Add_row with multi-index #415

info-rchitect opened this issue Sep 21, 2017 · 2 comments
Labels

Comments

@info-rchitect
Copy link

info-rchitect commented Sep 21, 2017

Hi,

I am trying to add a row of data to a DF with a multi-index and cannot figure out why this doesn't work. Any help is greatly appreciated.

[5] pry(main)> dset.data
=> #<Daru::DataFrame(8x9)>
                                     dataset       test   facility test_yield test_yield total_pass total_pass total_test total_test
        ds1      testA        png        ds1      testA        png       0.98        nil       98.0        nil      100.0        nil
                              suz        ds1      testA        suz        nil       0.97        nil       97.0        nil      100.0
                 testB        png        ds1      testB        png       0.79        nil       79.0        nil      100.0        nil
                              suz        ds1      testB        suz        nil       0.92        nil       92.0        nil      100.0
                 testC        png        ds1      testC        png       0.99        nil       99.0        nil      100.0        nil
                              suz        ds1      testC        suz        nil        0.9        nil       90.0        nil      100.0
                 testD        png        ds1      testD        png       0.86        nil       86.0        nil      100.0        nil
                              suz        ds1      testD        suz        nil       0.85        nil       85.0        nil      100.0

[8] pry(main)> new_row_index = dset.index.to_a[-2]
=> [:ds1, "testD", "png"]
[9] pry(main)> new_row_index[1] = "testE"
=> "testE"
[10] pry(main)> new_row_index
=> [:ds1, "testE", "png"]
[11] pry(main)> new_row_data = [:ds1, "testE", "png"] + [nil] * 6
=> [:ds1, "testE", "png", nil, nil, nil, nil, nil, nil]
[12] pry(main)> dset.add_row new_row_data, index: new_row_index
IndexError: element size differs (1 should be 3)

thx

EDIT

I tried using the same multi-index to edit an existing row and it worked just fine but the add-row method doesn't seem to like a similar index passed as an Array.

[20] pry(main)> dset.row[[:ds1, 'testA', 'png']]
=> #<Daru::Vector(9)>
                         ds1testApng
           dataset               ds1
              test             testA
          facility               png
   test_yield_amg1              0.999
   test_yield_amg2               nil
   total_pass_amg1              99.0
   total_pass_amg2               nil
 total_tested_amg1             100.0
 total_tested_amg2               nil
[21] pry(main)> dset.row[[:ds1, 'testA', 'png']] = [nil] * 9
=> [nil, nil, nil, nil, nil, nil, nil, nil, nil]
[22] pry(main)> dset.row[[:ds1, 'testA', 'png']]
=> #<Daru::Vector(9)>
                         ds1testApng
           dataset               nil
              test               nil
          facility               nil
   test_yield_amg1               nil
   test_yield_amg2               nil
   total_pass_amg1               nil
   total_pass_amg2               nil
 total_tested_amg1               nil
 total_tested_amg2               nil
[23] pry(main)> dset.add_row [nil]*9, index: [:ds1, 'testE', 'png']
IndexError: element size differs (1 should be 3)
from /home/user/.origen/gems/ruby/2.3.0/gems/daru-0.1.6/lib/daru/index/multi_index.rb:117:in `transpose'

Does anyone have an example of adding a row using a multi-index?

thx

@info-rchitect info-rchitect reopened this Sep 21, 2017
@info-rchitect info-rchitect changed the title Add_row with multi-inexexit! Add_row with multi-index Sep 24, 2017
@zverok zverok added the bug label Oct 2, 2017
@zverok
Copy link
Collaborator

zverok commented Oct 2, 2017

Thanks for the reporting! Fixed in #418. Until it is merged and released, you can just use (with the same effect, yet working):

dset.row[*new_row_index] = new_row_data

@zverok zverok closed this as completed Oct 2, 2017
@info-rchitect
Copy link
Author

thanks @zverok !

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

No branches or pull requests

2 participants