From: 5.5@... Date: 2018-04-07T01:09:36+00:00 Subject: [ruby-core:86473] [Ruby trunk Feature#12839] CSV - Give not nil but empty strings for empty fields Issue #12839 has been updated by 5.5 (5 5). Thank you very much for fixing #11126. But I think that the status of my ticket (#12839) should be not Closed but Rejected. Because my hope is that the CSV parser gives empty strings for empty fields. Using converters slows the speed. ~~~ gem "benchmark-ips" require "benchmark/ips" require "csv" csv_text = <(s){ s || "" } Benchmark.ips 20 do |r| r.report "without converter" do CSV.parse csv_text end r.report "with converter" do CSV.parse csv_text, converters: conv end r.compare! end # Comparison: # without converter: 9968.4 i/s # with converter: 8590.4 i/s - 1.16x slower ~~~ ---------------------------------------- Feature #12839: CSV - Give not nil but empty strings for empty fields https://bugs.ruby-lang.org/issues/12839#change-71411 * Author: 5.5 (5 5) * Status: Closed * Priority: Normal * Assignee: kou (Kouhei Sutou) * Target version: ---------------------------------------- The CSV parser gives nil for empty fields. ```rb require "csv" CSV.parse(%|,""|) #=> [[nil, ""]] ``` The above behavior maybe be suitable for certain programmers, but I hope to get `[["", ""]]`. So I had used to write the following code reluctantly till Ruby 2.1: ```rb require "csv" CSV.parse(%|,""|, converters: lambda{|v| v || ""}) #=> [["", ""]] ``` It is wasteful, but certainly works for my purpose. However, because of #11126, the above code does not work from Ruby 2.2. (Converters are not called for nil) I merely want an option, which makes the CSV parser give empty strings for empty fields. Namely, ```rb require "csv" CSV.parse(%|,""|, string: true) #=> [["", ""]] ``` -- https://bugs.ruby-lang.org/ Unsubscribe: