DelimitedFiles.jl icon indicating copy to clipboard operation
DelimitedFiles.jl copied to clipboard

more consistently ignore whitespace in readdlm

Open stevengj opened this issue 11 years ago • 3 comments

readcsv(IOBuffer(" 1, 2,3")) gives [1.0 2.0 3.0], but readcsv(IOBuffer(" 1 , 2,3")) gives [" 1 ", 2.0, 3.0].

As another example, readcsv(IOBuffer("\"hello, again\",\"goodbye\"")) gives ["hello, again" "goodbye"], but readcsv(IOBuffer(" \"hello, again\",\"goodbye\"")) gives " \"hello" " again\"" "goodbye". And readcsv(IOBuffer("\"hello, again\" ,\"goodbye\"")) gives an error (unexpected character ' ' after quoted field at row 1 column 1).

It seems like it would be better to treat all of these cases the same, and ignore whitespace before and after the delimiter.

stevengj avatar Sep 03 '14 15:09 stevengj

The first case seems fixed here:

julia> readcsv(IOBuffer(" 1, 2,3"))
1×3 Array{Float64,2}:
 1.0  2.0  3.0

julia> readcsv(IOBuffer(" 1 , 2,3"))
1×3 Array{Float64,2}:
 1.0  2.0  3.0

The other ones are the same as when the issue was made.

KristofferC avatar Jan 22 '17 12:01 KristofferC

Ok to close?

ViralBShah avatar Mar 12 '22 21:03 ViralBShah

The numeric case works now:

julia> readdlm(IOBuffer(" 1 , 2,3"), ',')
1×3 Matrix{Float64}:
 1.0  2.0  3.0

But the string behavior still seems odd to me:

julia> using DelimitedFiles

julia> readdlm(IOBuffer("\"hello, again\",\"goodbye\""), ',')
1×2 Matrix{Any}:
 "hello, again"  "goodbye"

julia> readdlm(IOBuffer(" \"hello, again\",\"goodbye\""), ',')
1×3 Matrix{Any}:
 " \"hello"  " again\""  "goodbye"

julia> readdlm(IOBuffer("\"hello, again\" ,\"goodbye\""), ',')
ERROR: unexpected character ' ' after quoted field at row 1 column 1
Stacktrace:

stevengj avatar Mar 12 '22 22:03 stevengj