SciRuby / daru

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

Vector#uniq fails on category vectors #514

Open parzydlo opened 5 years ago

parzydlo commented 5 years ago

I could not find information on whether this is expected bahaviour or not. It seems like the uniq method is missing in category.rb

>> v = Daru::Vector.new(['a','b','c'])
=> #<Daru::Vector(3)>
   0   a
   1   b
   2   c
>> v.uniq
=> #<Daru::Vector(3)>
   0   a
   1   b
   2   c
>> v.to_category.uniq
Traceback (most recent call last):
        5: from /Users/jan/.rvm/rubies/ruby-2.6.0/bin/irb:23:in `<main>'
        4: from /Users/jan/.rvm/rubies/ruby-2.6.0/bin/irb:23:in `load'
        3: from /Users/jan/.rvm/rubies/ruby-2.6.0/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        2: from (irb):14
        1: from /Users/jan/.rvm/gems/ruby-2.6.0/gems/daru-0.2.1/lib/daru/vector.rb:575:in `uniq'
NoMethodError (undefined method `uniq' for nil:NilClass)
ncs1 commented 4 years ago

When you create a Vector extending Daru::Category the data local member is nil, and so you receive this error. Looking on initialize_category & initialize_core_attributes (which are called on to_category and have access to the data) it isn't seem that the data member is being set. I don't know if it's an expected behavior.