# Having trouble implementating a Tables.jl row-table; when using BadukGoWeiqiTools, DataFrame(tbl) no longer works!

**URL:** <https://discourse.julialang.org/t/having-trouble-implementating-a-tables-jl-row-table-when-using-badukgoweiqitools-dataframe-tbl-no-longer-works/63622>\
**Category:** New to Julia\
**Created:** [June 27, 2021, 1:24am UTC](https://discourse.julialang.org/t/having-trouble-implementating-a-tables-jl-row-table-when-using-badukgoweiqitools-dataframe-tbl-no-longer-works/63622 "2021-06-27T01:24:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [June 27, 2021, 1:24am UTC](https://discourse.julialang.org/t/having-trouble-implementating-a-tables-jl-row-table-when-using-badukgoweiqitools-dataframe-tbl-no-longer-works/63622/1 "2021-06-27T01:24:47Z")

</div>

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](https://tables.juliadata.org/stable/#Tables.AbstractRow-1)

Here’s a MWE

```julia-auto
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.

```julia-auto
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

```

```julia-auto
versioninfo()

```

which is

```julia-auto
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/

```

#The `TableScraper.Table` implementation

> ****
>
> ``` import Tables # import Tables: istable, rowaccess, columnaccess, rows, columnnames, getcolumn, AbstractRow import Base: eltype, length, iterate
> 
> # 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
> 
> ```julia-auto
> </summary>
> ```

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [June 27, 2021, 1:36am UTC](https://discourse.julialang.org/t/having-trouble-implementating-a-tables-jl-row-table-when-using-badukgoweiqitools-dataframe-tbl-no-longer-works/63622/2 "2021-06-27T01:36:16Z")

</div>

somehow `DataFrame` calls `promote_type(:Type{Union{}}, ::Type{T})` indirectly for `T = String`.

```julia
promote_type(::Type{Union{}}, ::Type{T}) where T in Base at promotion.jl:224

```

But `WeakRefString.jl` defined the below, causing an ambiguity cos `Union{} <: InlineString` is `true`.

```julia
  promote_type(::Type{T}, ::Type{String}) where T<:InlineString in WeakRefStrings at c:\git\WeakRefStrings\src\inlinestrings.jl:44

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 27, 2021, 5:51am UTC](https://discourse.julialang.org/t/having-trouble-implementating-a-tables-jl-row-table-when-using-badukgoweiqitools-dataframe-tbl-no-longer-works/63622/3 "2021-06-27T05:51:44Z")

</div>

The ambiguity is caused by ` promote_type(::Type{T}, ::Type{String})`. Since every type is a supertype of `Union` (as it’s the bottom type in the type lattice), neither method is more specific than the other. I’d investigate/open an issue about why `DataFrames` calls that promotion in the first place, it [shouldn’t do that](https://youtu.be/TPuJsgyu87U?t=781). `WeakRefStrings` seems to be behaving correctly here, since their `T` is restricted to being subtypes of their own type.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [June 27, 2021, 12:27pm UTC](https://discourse.julialang.org/t/having-trouble-implementating-a-tables-jl-row-table-when-using-badukgoweiqitools-dataframe-tbl-no-longer-works/63622/4 "2021-06-27T12:27:38Z")

</div>

I think it is because WeakRefStrings overloaded `promote_rule` and not `promote_type`.

PR to fix [use promote\_rule not promote\_type by oxinabox · Pull Request #73 · JuliaData/WeakRefStrings.jl · GitHub](https://github.com/JuliaData/WeakRefStrings.jl/pull/73)  
PR to document this [Document that you should not overload promote\_type directly by oxinabox · Pull Request #41386 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/41386)  
(someone will come and tell me there if i am wrong)
