Actions
Bug #15967
closedTwo dimensional array which have CSV::Row object returns different result in ruby 2.3 and ruby 2.6
Description
I posted this issue at stackoverlow below.
Two dimensional array has the element which is CSV::Row object like this.
[[csv_row_object]]
I tried to flatten this array and got different result in ruby 2.3 and 2.6.
In the case of Ruby 2.3.8
[1] pry(main)> RUBY_VERSION
=> "2.3.8"
[2] pry(main)> filepath = "/Users/kota/Desktop/test.csv"
=> "/Users/kota/Desktop/test.csv"
[3] pry(main)> data = fixture_file_upload(filepath, "text/csv")
=> #<Rack::Test::UploadedFile:0x00007ffc51843988
@content_type="text/csv",
@original_filename="test.csv",
@tempfile=#<File:/var/folders/95/tnt69fz133z6s0b6tpxy0gqr0000gn/T/test.csv20190630-8692-11zzuh9>>
[4] pry(main)> require 'csv'
=> true
[5] pry(main)> parsed_csv = CSV.parse(data.read, headers:true, converters: nil)
=> #<CSV::Table mode:col_or_row row_count:4>
[6] pry(main)> parsed_csv[0]
=> #<CSV::Row "order_no":"10" "status":"1">
[7] pry(main)> parsed_csv[1]
=> #<CSV::Row "order_no":"20" "status":"1">
[8] pry(main)> parsed_csv[2]
=> #<CSV::Row "order_no":"30" "status":"1">
[9] pry(main)> array = [[parsed_csv[0]],[parsed_csv[1]],[parsed_csv[2]]]
=> [[#<CSV::Row "order_no":"10" "status":"1">], [#<CSV::Row "order_no":"20" "status":"1">], [#<CSV::Row "order_no":"30" "status":"1">]]
[10] pry(main)> array.flatten
=> [#<CSV::Row "order_no":"10" "status":"1">, #<CSV::Row "order_no":"20" "status":"1">, #<CSV::Row "order_no":"30" "status":"1">]
In the case of Ruby 2.6
[1] pry(main)> RUBY_VERSION
=> "2.6.0"
[2] pry(main)> filepath = "/Users/kota/Desktop/test.csv"
=> "/Users/kota/Desktop/test.csv"
[3] pry(main)> data = fixture_file_upload(filepath, "text/csv")
=> #<Rack::Test::UploadedFile:0x00007fc91d0a0828
@content_type="text/csv",
@original_filename="test.csv",
@tempfile=#<File:/var/folders/95/tnt69fz133z6s0b6tpxy0gqr0000gn/T/test.csv20190630-8971-rjpb5g>>
[4] pry(main)> require 'csv'
=> true
[5] pry(main)> parsed_csv = CSV.parse(data.read, headers:true, converters: nil)
=> #<CSV::Table mode:col_or_row row_count:4>
[6] pry(main)> parsed_csv[0]
=> #<CSV::Row "order_no":"10" "status":"1">
[7] pry(main)> parsed_csv[1]
=> #<CSV::Row "order_no":"20" "status":"1">
[8] pry(main)> parsed_csv[2]
=> #<CSV::Row "order_no":"30" "status":"1">
[9] pry(main)> array = [[parsed_csv[0]],[parsed_csv[1]],[parsed_csv[2]]]
=> [[#<CSV::Row "order_no":"10" "status":"1">], [#<CSV::Row "order_no":"20" "status":"1">], [#<CSV::Row "order_no":"30" "status":"1">]]
[10] pry(main)> array.flatten
=> ["order_no", "10", "status", "1", "order_no", "20", "status", "1", "order_no", "30", "status", "1"]
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Status changed from Open to Third Party's Issue
It seems a change in csv-1.0.2.
I guess it is an intentional feature, but not sure.
Please report it to the upstream, https://github.com/ruby/csv.
Updated by kou (Kouhei Sutou) over 4 years ago
- Status changed from Third Party's Issue to Rejected
- Assignee set to kou (Kouhei Sutou)
It's introduced by #10013.
Adding CSV::Row#to_ary
may be wrong. But I couldn't remove CSV::Row#to_ary
to avoid compatibility breakage again.
Actions
Like0
Like0Like0