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

Single row CSV: last value not parsed #4890

Closed
elehcim opened this issue Nov 22, 2013 · 4 comments
Closed

Single row CSV: last value not parsed #4890

elehcim opened this issue Nov 22, 2013 · 4 comments

Comments

@elehcim
Copy link
Contributor

elehcim commented Nov 22, 2013

Hi,
I just happened to find a weird behaviour of readcsv. Having a very long single line (1 row) file of comma separated values, I used the function readcsv() to import it but the last value was not imported. Adding a carriage return or another comma at the end of the line makes readcsv behaving correctly.

Examples:

file:

2,3,4,2
julia> w=open("1.csv"); e=readcsv(w); close(w); e
1x3 Array{Float64,2}:
 2.0  3.0  4.0

(where's the last "2"?)


file: (carriage return at the end of the line)

2,3,4,2

julia> w=open("1.csv"); e=readcsv(w); close(w); e
1x4 Array{Float64,2}:
 2.0  3.0  4.0  2.0

file: (comma at the end)

2,3,4,2,
julia> w=open("1.csv"); e=readcsv(w); close(w); e
1x4 Array{Float64,2}:
 2.0  3.0  4.0  2.0

This happens also with string values but it doesn't happen when the file has multiple rows.

@ViralBShah
Copy link
Member

Cc: @tanmaykm

@tanmaykm
Copy link
Member

Seems to be working fine on my setup.
Shall update to latest master and confirm.

@staticfloat
Copy link
Member

Note that tools like nano will automatically put a newline at the end of your file. Try the following to generate data that exhibits the problem:

$ echo -n "2,3,4,2" > test.csv
$ julia -e 'show(readcsv("test.csv")) && echo
1x3 Array{Float64,2}:
 2.0  3.0  4.0
$

I put the && echo there just so that we'd get a newline at the end of the output. This is on:

Julia Version 0.3.0-prerelease+73
Commit 8d44c8e* (2013-11-20 02:52 UTC)

@tanmaykm
Copy link
Member

Found the bug. Was there in my earlier setup as well. Shall push a fix shortly.

JeffBezanson added a commit that referenced this issue Nov 23, 2013
readcsv fix col count when no newline. fixes #4890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants