Skip to content

Commit fc46d3f

Browse files
author
Shashi Gowda
committed
1 parent 3dd9444 commit fc46d3f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/csv.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ function guesscolparsers(str::AbstractString, header, opts::LocalOpts, pos::Int,
475475
guess = []
476476
prevfields = String[]
477477

478+
givenkeys = !isempty(colparsers) ? first.(collect(optionsiter(colparsers, header))) : []
478479
for i=1:nrows
479480
pos, _ = eatnewlines(str, pos)
480481
if pos > endof(str)
@@ -499,6 +500,9 @@ function guesscolparsers(str::AbstractString, header, opts::LocalOpts, pos::Int,
499500

500501
# update guess
501502
for j in 1:length(guess)
503+
if j in givenkeys
504+
continue # user specified this
505+
end
502506
if length(fields) != length(guess)
503507
error("previous rows had $(length(guess)) fields but row $i has $(length(fields))")
504508
end

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ import TextParse: _csvread
419419

420420
# shouldn't fail because y doesn't exist
421421
@test _csvread("x\n1", colparsers=Dict("y"=>String)) == (([1],), ["x"])
422+
423+
# Don't try to guess type if it's provided by user. Issue JuliaDB.jl#109
424+
s="""
425+
time,value
426+
"2017-11-09T07:00:07.391101180",0
427+
"""
428+
@test _csvread(s, colparsers=Dict(:time=>String)) == ((String["2017-11-09T07:00:07.391101180"], [0]), String["time", "value"])
422429
end
423430

424431
@testset "skiplines_begin" begin

0 commit comments

Comments
 (0)