diff --git a/src/guesstype.jl b/src/guesstype.jl index 3514852..7587fed 100644 --- a/src/guesstype.jl +++ b/src/guesstype.jl @@ -52,7 +52,7 @@ function getquotechar(x) return '\0' end -function guesstoken(x, opts, prevent_quote_wrap, @nospecialize(prev_guess)=Unknown(), nastrings=NA_STRINGS, stringarraytype=StringArray) +function guesstoken(x, opts, prevent_quote_wrap, @nospecialize(prev_guess=Unknown()), nastrings=NA_STRINGS, stringarraytype=StringArray) q = getquotechar(x) if isa(prev_guess, StringToken) @@ -65,8 +65,14 @@ function guesstoken(x, opts, prevent_quote_wrap, @nospecialize(prev_guess)=Unkno else prev_inner = prev_guess end - inner_token = guesstoken(strip(strip(x, q)), opts, true, prev_inner, nastrings, stringarraytype) - return Quoted(inner_token, opts.quotechar, opts.escapechar) + inner_string = strip(strip(x, q)) + if inner_string=="" + # If we come across a "", we classify it as a string column no matter what + return Quoted(StringToken(stringarraytype<:StringArray ? StrRange : String), opts.quotechar, opts.escapechar) + else + inner_token = guesstoken(inner_string, opts, true, prev_inner, nastrings, stringarraytype) + return Quoted(inner_token, opts.quotechar, opts.escapechar) + end elseif isa(prev_guess, Quoted) # but this token is not quoted return Quoted(guesstoken(x, opts, true, prev_guess.inner, nastrings, stringarraytype), opts.quotechar, opts.escapechar) diff --git a/test/runtests.jl b/test/runtests.jl index 79b5cc6..f139909 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -370,11 +370,11 @@ import TextParse: guesstoken, Unknown, Numeric, DateTimeToken, StrRange @test guesstoken("\"1\"", opts, false, Quoted(Numeric(Int), opts.quotechar, opts.escapechar)) == Quoted(Numeric(Int), opts.quotechar, opts.escapechar) # Test quoting with Nullable tokens - @test guesstoken("\"\"", opts, false, Quoted(Unknown(), opts.quotechar, opts.escapechar)) == Quoted(NAToken(Unknown()), opts.quotechar, opts.escapechar) - @test guesstoken("\"\"", opts, false, Quoted(NAToken(Unknown()), opts.quotechar, opts.escapechar)) == Quoted(NAToken(Unknown()), opts.quotechar, opts.escapechar) - @test guesstoken("\"\"", opts, false, Quoted(Numeric(Int), opts.quotechar, opts.escapechar)) == Quoted(NAToken(Numeric(Int)), opts.quotechar, opts.escapechar) - @test guesstoken("\"\"", opts, false, Unknown()) == Quoted(NAToken(Unknown()), opts.quotechar, opts.escapechar) - @test guesstoken("\"\"", opts, false, Numeric(Int)) == Quoted(NAToken(Numeric(Int)), opts.quotechar, opts.escapechar) + @test guesstoken("\"\"", opts, false, Quoted(Unknown(), opts.quotechar, opts.escapechar)) == Quoted(StringToken(StrRange), opts.quotechar, opts.escapechar) + @test guesstoken("\"\"", opts, false, Quoted(NAToken(Unknown()), opts.quotechar, opts.escapechar)) == Quoted(StringToken(StrRange), opts.quotechar, opts.escapechar) + @test guesstoken("\"\"", opts, false, Quoted(Numeric(Int), opts.quotechar, opts.escapechar)) == Quoted(StringToken(StrRange), opts.quotechar, opts.escapechar) + @test guesstoken("\"\"", opts, false, Unknown()) == Quoted(StringToken(StrRange), opts.quotechar, opts.escapechar) + @test guesstoken("\"\"", opts, false, Numeric(Int)) == Quoted(StringToken(StrRange), opts.quotechar, opts.escapechar) @test guesstoken("", opts, false, Quoted(Numeric(Int), opts.quotechar, opts.escapechar)) == Quoted(NAToken(Numeric(Int)), opts.quotechar, opts.escapechar) @test guesstoken("", opts, false, Quoted(NAToken(Numeric(Int)), opts.quotechar, opts.escapechar)) == Quoted(NAToken(Numeric(Int)), opts.quotechar, opts.escapechar) @test guesstoken("1", opts, false, Quoted(NAToken(Numeric(Int)), opts.quotechar, opts.escapechar)) == Quoted(NAToken(Numeric(Int)), opts.quotechar, opts.escapechar)