Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundsError on join #237

Closed
MaximilianJHuber opened this issue Apr 13, 2019 · 1 comment
Closed

BoundsError on join #237

MaximilianJHuber opened this issue Apr 13, 2019 · 1 comment

Comments

@MaximilianJHuber
Copy link

On JuliaDB 0.12 and IndexedTables 0.12:

using JuliaDB, Dates

t1 = table((date = [Date(2008,12,31), Date(2009,12,31), Date(2010,12,31)], ))
t2 = table((date = [Date(2008,12,31), Date(2009,12,31)], value = [1,2]))

join(t1, t2, how = :left, lkey = :date, rkey = :date)

throws:

BoundsError: attempt to access StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}} with indices 1:0 at index [1]

Stacktrace:
 [1] throw_boundserror(::StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}}, ::Tuple{Int64}) at .\abstractarray.jl:484
 [2] checkbounds at .\abstractarray.jl:449 [inlined]
 [3] macro expansion at C:\Users\Max\.julia\packages\StructArrays\Du4zZ\src\structarray.jl:125 [inlined]
 [4] getindex at C:\Users\Max\.julia\packages\StructArrays\Du4zZ\src\structarray.jl:122 [inlined]
 [5] #261 at .\none:0 [inlined]
 [6] iterate at .\generator.jl:47 [inlined]
 [7] _piterate at .\iterators.jl:814 [inlined]
 [8] _piterate at .\iterators.jl:816 [inlined]
 [9] iterate at .\iterators.jl:822 [inlined]
 [10] iterate at .\generator.jl:44 [inlined]
 [11] foreach(::getfield(IndexedTables, Symbol("##265#275")){NamedTuple{(),Tuple{}},NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},NamedTuple{(:date,),Tuple{Date}},StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},NamedTuple{(:left, :right),Tuple{StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Union{Missing, Int64},1}}}}}}}, ::Base.Generator{Base.Iterators.ProductIterator{Tuple{Base.Generator{UnitRange{Int64},getfield(IndexedTables, Symbol("##262#272")){StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Int64,1}}}},Array{Int64,1}}},Base.Generator{UnitRange{Int64},getfield(IndexedTables, Symbol("##261#271")){StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},Array{Int64,1}}}}},typeof(reverse)}) at .\abstractarray.jl:1835
 [12] (::getfield(IndexedTables, Symbol("#iterate_value_push_key#270")){NamedTuple{(),Tuple{}},NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},false,DataType,Nothing,Nothing,StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},NamedTuple{(:left, :right),Tuple{StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Union{Missing, Int64},1}}}}}},typeof(IndexedTables.concat_tup),StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Int64,1}}}},StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Array{Int64,1},Bool,Bool})(::Tuple{UnitRange{Int64},UnitRange{Int64}}) at C:\Users\Max\.julia\packages\IndexedTables\DgX0A\src\join.jl:62
 [13] foreach(::getfield(IndexedTables, Symbol("#iterate_value_push_key#270")){NamedTuple{(),Tuple{}},NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},false,DataType,Nothing,Nothing,StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},NamedTuple{(:left, :right),Tuple{StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Union{Missing, Int64},1}}}}}},typeof(IndexedTables.concat_tup),StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Int64,1}}}},StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Array{Int64,1},Bool,Bool}, ::Base.Iterators.Filter{getfield(IndexedTables, Symbol("##259#268")),StructArrays.GroupJoinPerm{StructArrays.GroupPerm{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Base.OneTo{Int64}},StructArrays.GroupPerm{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Base.OneTo{Int64}}}}) at .\abstractarray.jl:1835
 [14] #_join!#256(::Type, ::Nothing, ::Nothing, ::Function, ::StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}}, ::NamedTuple{(:left, :right),Tuple{StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Union{Missing, Int64},1}}}}}}, ::Val{:left}, ::Val{false}, ::typeof(IndexedTables.concat_tup), ::StructArrays.GroupJoinPerm{StructArrays.GroupPerm{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Base.OneTo{Int64}},StructArrays.GroupPerm{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Base.OneTo{Int64}}}, ::StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}}, ::StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Int64,1}}}}) at C:\Users\Max\.julia\packages\IndexedTables\DgX0A\src\join.jl:72
 [15] (::getfield(IndexedTables, Symbol("#kw##_join!")))(::NamedTuple{(:missingtype, :init_group, :accumulate),Tuple{DataType,Nothing,Nothing}}, ::typeof(IndexedTables._join!), ::StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}}, ::NamedTuple{(:left, :right),Tuple{StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}},StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Union{Missing, Int64},1}}}}}}, ::Val{:left}, ::Val{false}, ::Function, ::StructArrays.GroupJoinPerm{StructArrays.GroupPerm{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Base.OneTo{Int64}},StructArrays.GroupPerm{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}},Array{Int64,1},Base.OneTo{Int64}}}, ::StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}}, ::StructArrays.StructArray{NamedTuple{(:value,),Tuple{Union{Missing, Int64}}},1,NamedTuple{(:value,),Tuple{Array{Int64,1}}}}) at .\none:0
 [16] #join#276(::Symbol, ::Bool, ::Symbol, ::Symbol, ::Tuple{}, ::Tuple{Int64}, ::Nothing, ::Bool, ::Type, ::Nothing, ::Nothing, ::typeof(join), ::typeof(IndexedTables.concat_tup), ::IndexedTable{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}}}, ::IndexedTable{StructArrays.StructArray{NamedTuple{(:date, :value),Tuple{Date,Int64}},1,NamedTuple{(:date, :value),Tuple{Array{Date,1},Array{Int64,1}}}}}) at C:\Users\Max\.julia\packages\IndexedTables\DgX0A\src\join.jl:187
 [17] (::getfield(Base, Symbol("#kw##join")))(::NamedTuple{(:how, :lkey, :rkey),Tuple{Symbol,Symbol,Symbol}}, ::typeof(join), ::Function, ::IndexedTable{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}}}, ::IndexedTable{StructArrays.StructArray{NamedTuple{(:date, :value),Tuple{Date,Int64}},1,NamedTuple{(:date, :value),Tuple{Array{Date,1},Array{Int64,1}}}}}) at .\none:0
 [18] #join#277 at C:\Users\Max\.julia\packages\IndexedTables\DgX0A\src\join.jl:197 [inlined]
 [19] (::getfield(Base, Symbol("#kw##join")))(::NamedTuple{(:how, :lkey, :rkey),Tuple{Symbol,Symbol,Symbol}}, ::typeof(join), ::IndexedTable{StructArrays.StructArray{NamedTuple{(:date,),Tuple{Date}},1,NamedTuple{(:date,),Tuple{Array{Date,1}}}}}, ::IndexedTable{StructArrays.StructArray{NamedTuple{(:date, :value),Tuple{Date,Int64}},1,NamedTuple{(:date, :value),Tuple{Array{Date,1},Array{Int64,1}}}}}) at .\none:0
 [20] top-level scope at In[3]:5

But the following is fine:

using JuliaDB, Dates

t1 = table((date = [Date(2008,12,31), Date(2009,12,31), Date(2010,12,31)], height = [4,5,6]))
t2 = table((date = [Date(2008,12,31), Date(2009,12,31)], value = [1,2]))

join(t1, t2, how = :left, lkey = :date, rkey = :date)
@piever
Copy link
Collaborator

piever commented Apr 14, 2019

The issue is that rows(t, cols) , whenever cols is empty, returns that funny object:StructArrays.StructArray{NamedTuple{(),Tuple{}},1,NamedTuple{(),Tuple{}}} with indices 1:0. When join tries to access it, it errors. The problem is that rows(t, cols) can't be a StructArray of the correct length because the length of the StructArray is the length of the columns and without columns this is undefined. Here I think the current solution (creating something with 0 length) is not ideal. I guess we could change rows(t, cols) to return fill(NamedTuple(), length(t)) so that length and eltype are correct, in which case I imagine join should work out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants