Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more consistently ignore whitespace in readdlm #4

Open
stevengj opened this issue Sep 3, 2014 · 3 comments
Open

more consistently ignore whitespace in readdlm #4

stevengj opened this issue Sep 3, 2014 · 3 comments
Labels

Comments

@stevengj
Copy link
Contributor

stevengj commented Sep 3, 2014

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.

@JeffBezanson JeffBezanson removed the I/O label Jul 10, 2015
@KristofferC
Copy link
Collaborator

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.

@ViralBShah
Copy link
Contributor

Ok to close?

@stevengj
Copy link
Contributor Author

stevengj commented Mar 12, 2022

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:

@ViralBShah ViralBShah added the I/O label Mar 13, 2022
@ViralBShah ViralBShah transferred this issue from JuliaLang/julia Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants