Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Andy Hartford
RE: error deleting headers with "blank" rows [ reply ]  
2010-01-07 21:48
Yup, that fixes it! Thanks for the fast response.

I'll be looking forward to your next release.

By: James Gray
RE: error deleting headers with "blank" rows [ reply ]  
2010-01-07 17:15
I've checked a slightly modified version of your fix into Subversion. Can you give it a shot and tell me if it fixed your problem?

By: Andy Hartford
error deleting headers with "blank" rows [ reply ]  
2010-01-07 02:14
Hi!

First of all thanks for the very useful library.

I'm getting an error trying to delete a column from a FasterCSV::Table when it contains "blank" rows. Here's a pretty simple code example. I'm seeing this behavior with 1.5.0.

csv = "col1,col2\nra1,ra2\n\nrb1,rb2"
table = FasterCSV.new(StringIO.new(csv, "r"), :headers => true).read
table.delete "col2"

The last line gets this error:
TypeError: no implicit conversion from nil to integer
from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.5.0/lib/faster_csv.rb:255:in `delete_at'
from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.5.0/lib/faster_csv.rb:255:in `delete'
from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.5.0/lib/faster_csv.rb:637:in `delete'
from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.5.0/lib/faster_csv.rb:637:in `map'
from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.5.0/lib/faster_csv.rb:637:in `delete'
from (irb):20


After investigating, it seems that Row#delete is being called on the "blank" row which has an @row instance variable of []. On line 255, index is returning nil which is being passed to Array#delete_at causing the error. I hope that's clear.

A possible solution that occurred to me is to rewrite line 255 with:

if i = index(header_or_index, minimum_index)
@row.delete_at i
end

Although it's possible something bad is happening earlier to cause the @row of [].

Thanks!

Andy