I have checked through the other posts on implementing the Tables.jl row interface and I think I’ve implemented everything in the Tables.jl row-table interface
Here’s a MWE
using TableScraper, DataFrames
tbl = TableScraper.Table([["abc" for _ in 1:9] for j in 1:1], "names".*string.(1:9))
DataFrame(tbl) #this works!
using WeakRefStrings # the culprit
DataFrame(tbl) #the same code now fails
which gives this perplexing error.
Why does using WeakRefStrings
change how DataFrame(tbl)
works? This is really odd.
How do I go about debugging this? I tried tracing through the code, but the same code is called. A bit out of ideas at the moment.
ERROR: MethodError: promote_type(::Type{Union{}}, ::Type{String}) is ambiguous. Candidates:
promote_type(::Type{Union{}}, ::Type{T}) where T in Base at promotion.jl:224
promote_type(::Type{T}, ::Type{String}) where T<:WeakRefStrings.InlineString in WeakRefStrings at C:\Users\RTX2080\.julia\packages\WeakRefStrings\a3jYm\src\inlinestrings.jl:44
Possible fix, define
promote_type(::Type{Union{}}, ::Type{String})
Stacktrace:
[1] add_or_widen!(val::String, col::Int64, nm::Symbol, dest::Tables.EmptyVector, row::Int64, updated::Base.RefValue{Any}, L::Base.HasLength)
@ Tables C:\Users\RTX2080\.julia\packages\Tables\gg6Id\src\fallbacks.jl:150
[2] eachcolumns
@ C:\Users\RTX2080\.julia\packages\Tables\gg6Id\src\utils.jl:127 [inlined]
[3] _buildcolumns(rowitr::Tables.IteratorWrapper{TableScraper.Table}, row::Tables.IteratorRow{TableScraper.TableRow}, st::Int64, sch::Tables.Schema{(:names1, :names2, :names3, :names4, :names5, :names6, :names7, :names8, :names9), nothing}, columns::NTuple{9, Tables.EmptyVector}, updated::Base.RefValue{Any})
@ Tables C:\Users\RTX2080\.julia\packages\Tables\gg6Id\src\fallbacks.jl:187
[4] buildcolumns
@ C:\Users\RTX2080\.julia\packages\Tables\gg6Id\src\fallbacks.jl:217 [inlined]
[5] columns
@ C:\Users\RTX2080\.julia\packages\Tables\gg6Id\src\fallbacks.jl:262 [inlined]
[6] DataFrame(x::TableScraper.Table; copycols::Nothing)
@ DataFrames C:\Users\RTX2080\.julia\packages\DataFrames\nxjiD\src\other\tables.jl:58
[7] DataFrame(x::TableScraper.Table)
@ DataFrames C:\Users\RTX2080\.julia\packages\DataFrames\nxjiD\src\other\tables.jl:49
[8] top-level scope
@ REPL[144]:1
versioninfo()
which is
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS = 6
JULIA_PKG_DEVDIR = c:/git/
a table structure local to TableScraper
struct Table
rows
columnnames
end
struct TableRow <: Tables.AbstractRow
row::Int
source::Table
end
Tables.istable(::Table)=true
Tables.rowaccess(::Table)=true
Tables.columnaccess(::Table)=true
Tables.columnnames(t::Table)=t.columnnames
Tables.rows(t::Table)=t
Base.eltype(::Table) = TableRow
Base.length(t::Table) = length(t.rows)
Base.iterate(t::Table, st = 1) = st > length(t) ? nothing : (TableRow(st, t), st+1)
function Tables.getcolumn(t::TableRow, ::Type, col::Int, nm::Symbol)
tbl = getfield(t, :source)
row = tbl.rows[t.row]
row[col]
end
function Tables.getcolumn(t::TableRow, i::Int)
tbl = getfield(t, :source)
row_num = getfield(t, :row)
row = tbl.rows[row_num]
row[i]
end
function Tables.getcolumn(t::TableRow, nm::Symbol)
tbl = getfield(t, :source)
row_num = getfield(t, :row)
row = tbl.rows[row_num]
col = indexin([string(nm)], tbl.columnnames)[1]
row[col]
end
function Tables.getcolumn(t::TableRow, nm::String)
Tables.getcolumn(t, Symbol(nm))
end
Tables.columnnames(t::TableRow) = getfield(t, :source).columnnames
</summary>