DelimitedFiles.jl
DelimitedFiles.jl copied to clipboard
more consistently ignore whitespace in readdlm
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.
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.
Ok to close?
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: