SciRuby / daru

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

Passing blocks into from_csv method doesn't work unless &block added as parameter. #325

Closed gusandrianos closed 7 years ago

gusandrianos commented 7 years ago

Hello guys. I'm working on #308 but whenever I try to pass a block to test the code, it doesn't work. It only works if I add &block into from_csv and the methods it calls.

After using a simple block like {|x| x.each{|row| row.each{|elem| puts elem}}} the test fails, because

1) Daru::IO Daru::DataFrame.from_csv performs an action on a row or rows before importing from CSV using block_given?
     Failure/Error: return array if array.size == array.uniq.size

     NoMethodError:
       undefined method `size' for nil:NilClass
     # ./lib/daru/helpers/array.rb:12:in `recode_repeated'
     # ./lib/daru/io/io.rb:220:in `from_csv_hash'
     # ./lib/daru/io/io.rb:86:in `from_csv'
     # ./lib/daru/dataframe.rb:48:in `from_csv'
     # ./spec/io/io_spec.rb:37:in `block (4 levels) in <top (required)>'

Has anyone actually used a block of code for modifying the rows before creating a new DataFrame? Honestly I think it's not supposed to be this way, it creates more problems than it solves and it's more natural to import something and then modify it.

Let me know what you think. Should I open a pull request?

P.S x is of class CSV, row of Array and elem of String