 |
Forums |
Admin Discussion Forums: help Start New Thread
| Message: 92239 |
 |
BY: Andy Hartford (shngn) DATE: 2010-01-07 02:14 SUBJECT: error deleting headers with "blank" rows 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 | |
Thread View
Post a followup to this message
|
 |