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

Counting nil. confusing #487

Open
kojix2 opened this issue Feb 9, 2019 · 11 comments
Open

Counting nil. confusing #487

kojix2 opened this issue Feb 9, 2019 · 11 comments

Comments

@kojix2
Copy link
Member

kojix2 commented Feb 9, 2019

require 'daru'
v = Daru::Vector.new [1,2,3,nil,nil]

v.count nil
# => 3

v.count 1
# => 1

v.count(1){ |i| i == nil}
# => 2

v.count_values nil
# => 2
@Shekharrajak
Copy link
Member

I thinnk, count method is not defined, but we have block :

v.count do  |i|
 i == 1 
end

count_values is defined here.

Yes, it is confusing and should have better API, return value and documentation.

@Sylfrena
Copy link
Contributor

Sylfrena commented Mar 21, 2019

@Shekharrajak
Hello, I'm new here and would like to give this issue a try. I am aware of the count method in Ruby and have played around with the count_values method too. However, I am unable to understand the exact objective of this issue. Do you require better documentation/functionality for the count-values method or are looking to implement an equivalent of the count method?

@Shekharrajak
Copy link
Member

Shekharrajak commented Mar 21, 2019

@Sylfrena , I encourage you to first setup the development version and try out few examples present in documentation and play with it.

Also try Ruby array count method and find out what should be expected value for daru vector with nil values.

I feel @kojix2 , is trying to say that we get different values for count when it is with block. Right @kojix2 ?

@Shekharrajak
Copy link
Member

I see there are 3 methods count, value_counts and count_values.

count :

Retrieves number of cases which comply condition. If block given,
retrieves number of instances where block returns true. If other
values given, retrieves the frequency for this value. If no value
 given, counts the number of non-nil elements in the Vector.

I think, it should be able to count the nil values as well like count_values:

[14] pry(main)> v2
=> #<Daru::Vector(7)>
   0   1
   1   2
   2   2
   3   3
   4   3
   5 nil
   6 nil
[15] pry(main)> v2.count_values
=> 0 # here it should behave same as value_counts. ie.e occurrences of each value in the Vector
[16] pry(main)> v2.count_values(3)
=> 2
[17] pry(main)> v2.count_values(1)
=> 1
[18] pry(main)> v2.count_values(nil)
=> 2
[19] pry(main)> v2.value_counts
=> #<Daru::Vector(4)>
   1   1
   2   2
   3   2
       2

So here count can have block but count_values can't. I see this is the only difference, I see. WDYT @v0dro

@Sylfrena
Copy link
Contributor

@Shekharrajak
I went through documentation and played around more with some of the functionalities that Daru offers. I tried count , count_values and value_counts methods on daru vectors as well. Pertaining to this issue and your previous comment, I think that the following modifications need to be made:

  1. Override count method in Vector class to ensure it can recognize nil values as well.
  2. Modify count_values so that it behaves same as value_counts when no argument is passed to it.

However, I have been unable to setup the development version. On running bundle exec rspec, the build fails and I am unable to figure out how to solve it.

@Shekharrajak
Copy link
Member

@Sylfrena , I hope, you have gone through this step by step.

@Sylfrena
Copy link
Contributor

@Shekharrajak
Hi! Yes, I made sure to follow all instructions before trying to bundle exec rspec. I didn't install all ruby versions though because it was mentioned optional. Could that be a possible reason for the test suite failing?

@Shekharrajak
Copy link
Member

@Sylfrena , can you please open an issue and paste the error log there, so that we can track it (also please mention the commands you run) ? Thanks!

@Shekharrajak
Copy link
Member

@Sylfrena , can you please check whether you are able to run examples present in readme file or not ?

Basically you just have to run bundle install and bundle console inside the your cloned folder and try something like :

data_frame = Daru::DataFrame.new(
  {
    'Beer' => ['Kingfisher', 'Snow', 'Bud Light', 'Tiger Beer', 'Budweiser'],
    'Gallons sold' => [500, 400, 450, 200, 250]
  },
  index: ['India', 'China', 'USA', 'Malaysia', 'Canada']
)
data_frame

Let me know if it is working properly.

@Sylfrena
Copy link
Contributor

@Shekharrajak
Hi. I was able to run the above and other examples I tried in daru. I opened an issue here.

@Shekharrajak
Copy link
Member

@Sylfrena , it looks like there is some problem. Meanwhile other than running rspec, you can work on fixing any other issue and send us PR. We will check the travis build result for the PR as well.

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