Skip to content

Commit

Permalink
Merge pull request #4894 from tanmaykm/master
Browse files Browse the repository at this point in the history
readcsv fix col count when no newline. fixes #4890
  • Loading branch information
JeffBezanson committed Nov 23, 2013
2 parents 6e6e093 + dab217b commit b406675
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ function dlm_dims{T,D}(dbuff::T, eol::D, dlm::D)
catch ex
error("at row $nrows, column $col : $ex)")
end
(col > 0) && (nrows += 1)
if col > 0
nrows += 1
ncols = max(ncols, col+1)
end
ncols = max(ncols, col, 1)
nrows = max(nrows, 1)
return (nrows, ncols)
Expand Down
8 changes: 8 additions & 0 deletions test/readdlm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ dlm_data = readdlm(joinpath("perf", "kernel", "imdb-1.tsv"), '\t')
@test dlm_data[12345,2] == "Gladiator"
@test dlm_data[31383,3] == 2005
@test dlm_data[1,1] == "McClure, Marc (I)"

@test size(readcsv(IOBuffer("1,2,3,4"))) == (1,4)
@test size(readcsv(IOBuffer("1,2,3,"))) == (1,4)
@test size(readcsv(IOBuffer("1,2,3,4\n"))) == (1,4)
@test size(readcsv(IOBuffer("1,2,3,\n"))) == (1,4)
@test size(readcsv(IOBuffer("1,2,3,4\n1,2,3,4"))) == (2,4)
@test size(readcsv(IOBuffer("1,2,3,4\n1,2,3,"))) == (2,4)
@test size(readcsv(IOBuffer("1,2,3,4\n1,2,3"))) == (2,4)

0 comments on commit b406675

Please sign in to comment.