Interpreting error message / stacktrace for CSV.File

System: macOS 10.15.7
Julia version 1.6

I use R heavily for data analysis in the life sciences and am slowly learning Julia for similar tasks with DataFrames.jl and CSV.jl. Recently I was tripped up by a small error and would like to learn how I could improve my reading of Julia’s error messages.

How could I have improved my approach to diagnosing the following bug?

I made this call:

               normalizenames = true,
               missingstring = ["", "NULL", "NA"])

and received this Error/stacktrace:

ERROR: MethodError: no method matching contains(::Vector{String}, ::String)
Closest candidates are:
  contains(::AbstractString, ::Any) at strings/util.jl:98
  contains(::Any) at strings/util.jl:159
 [1] Header
   @ ~/.julia/packages/CSV/CJfFO/src/header.jl:155 [inlined]
 [2] CSV.File(source::String; header::Int64, normalizenames::Bool, datarow::Int64, skipto::Nothing, footerskip
::Int64, transpose::Bool, comment::Nothing, use_mmap::Nothing, ignoreemptylines::Bool, select::Nothing, drop::
Nothing, missingstrings::Vector{String}, missingstring::Vector{String}, delim::Nothing, ignorerepeated::Bool, 
quotechar::Char, openquotechar::Nothing, closequotechar::Nothing, escapechar::Char, dateformat::Nothing, dateformats::Nothing, decimal::UInt8, truestrings::Vector{String}, falsestrings::Vector{String}, type::Nothing, types::Nothing, typemap::Dict{Type, Type}, pool::Float64, lazystrings::Bool, strict::Bool, silencewarnings::Bool, debug::Bool, parsingdebug::Bool, kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}
   @ CSV ~/.julia/packages/CSV/CJfFO/src/file.jl:217

I didn’t look at strings/util.jl as I suspected the error lay in my CSV.File call. I did look at header.jl and file.jl at the lines mentioned in the stacktrace. Neither were revealing.

There seems to be a mismatch of the argument signature but beyond that I found no clue to which argument.

Eventually, I figured out that it was a typo. There are two similar keyword arguments in CSV.File: missingstring and missingstrings. I had used the singular and given a vector with more than one value. Note that both arguments take a Vector{String} type missingstrings::Vector{String}, missingstring::Vector{String}.

Any recommendations on a better approach to reading the error message would be appreciated. It does seem that missingstring[s] should be made into one keyword argument that can take one or more values.

Hm, I don’t think there is a better approach here - keyword arguments don’t participate in dispatch, so the Methoderror only happens further down the function which always makes it harder to figure out.

I would argue that this particular case with two almost identical kwargs that take different input types might warrant an argument check with a specific error message for your case, maybe open an issue?

1 Like

Thank you. Will take your suggestion about opening an issue.

1 Like