Hi there,
I am importing multiple csv files using the excellent CSV.jl package. However, I fail to import all files in one go when one of the imported variables has the variable name “name”.
Is this a bug, and can someone recommend a workaround? In my real example, I cannot change the content of the csv files I am importing.
I could of course import only one file at a time, but I like the idea of importing them all in one go.
MWE:
using CSV
# Data with ordinary variable names - works
data = [
"a,b,c\n1,2,3\n4,5,6\n",
"a,b,c\n7,8,9\n10,11,12\n",
]
CSV.File(map(IOBuffer, data)) # Works
# Only one set of data with variable name "name" - works
data = [
"a,name,c\n1,2,3\n4,5,6\n",
]
CSV.File(map(IOBuffer, data)) # Works
# Data where the second variable name is "name" - fails
data = [
"a,name,c\n1,2,3\n4,5,6\n",
"a,name,c\n7,8,9\n10,11,12\n",
]
CSV.File(map(IOBuffer, data)) # Fails
REPL output:
4-element CSV.File:
CSV.Row: (a = 1, b = 2, c = 3)
CSV.Row: (a = 4, b = 5, c = 6)
CSV.Row: (a = 7, b = 8, c = 9)
CSV.Row: (a = 10, b = 11, c = 12)
2-element CSV.File:
CSV.Row: (a = 1, name = 2, c = 3)
CSV.Row: (a = 4, name = 5, c = 6)
ERROR: MethodError: Cannot `convert` an object of type SentinelArrays.ChainedVector{Int64, Vector{Int64}} to an object of type String
Closest candidates are:
convert(::Type{String}, ::WeakRefStrings.WeakRefString) at C:\Users\B046326\.julia\packages\WeakRefStrings\31nkb\src\WeakRefStrings.jl:81
convert(::Type{String}, ::FilePathsBase.AbstractPath) at C:\Users\B046326\.julia\packages\FilePathsBase\9kSEl\src\path.jl:117
convert(::Type{String}, ::String) at essentials.jl:218
...
Stacktrace:
[1] CSV.File(name::SentinelArrays.ChainedVector{Int64, Vector{Int64}}, names::Vector{Symbol}, types::Vector{Type}, rows::Int64, cols::Int64, columns::Vector{CSV.Column}, lookup::Dict{Symbol, CSV.Column})
@ CSV C:\Users\B046326\.julia\packages\CSV\b8ebJ\src\file.jl:106
[2] CSV.File(sources::Vector{IOBuffer}; source::Nothing, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ CSV C:\Users\B046326\.julia\packages\CSV\b8ebJ\src\file.jl:940
[3] CSV.File(sources::Vector{IOBuffer})
@ CSV C:\Users\B046326\.julia\packages\CSV\b8ebJ\src\file.jl:891
[4] top-level scope
@ c:\Users\B046326\Levy\projects\bam_io\test\temp.jl:150
julia>