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

Daru::Core::GroupBy#each_group #get_group not work with newly created index. #490

Open
kojix2 opened this issue Feb 25, 2019 · 3 comments
Open

Comments

@kojix2
Copy link
Member

kojix2 commented Feb 25, 2019

Hi
I found that each_group and get_group method do not work as expected when you set a new index.
For example:

require 'daru'
df = Daru::DataFrame.new(
    x: [1,2,3,4,5,6],
    z: %w(a a b b c c))
df.index = [1,2,3,4,5,6]

gr = df.group_by(:z)
 
gr.each_group{|g| p g}
##<Daru::DataFrame(2x2)>
#       x   z
#   1   2   a
#   2   3   b
##<Daru::DataFrame(2x2)>
#       x   z
#   3   4   b
#   4   5   c
#NoMethodError: undefined method `size' for nil:NilClass
#gems/daru-0.2.1/lib/daru/dataframe.rb:168:in `block in rows'

gr.get_group("a")
#NoMethodError: undefined method `each' for nil:NilClass
#gems/daru-0.2.1/lib/daru/core/group_by.rb:262:in `get_group'

Sorry if this is duplicated issue.

@kojix2
Copy link
Member Author

kojix2 commented Feb 25, 2019

# gr.get_group("a")
gr.get_group(["a"])

@kojix2
Copy link
Member Author

kojix2 commented Feb 25, 2019

This line.

rows = indexes.each.map { |idx| transpose[idx] }

transpose[idx] work as expected only when index is 0,1,2,...

@Shekharrajak
Copy link
Member

Thanks for pointing out this error. Someone will surely look into it.

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

3 participants