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

Bug in setindex #217

Open
aaowens opened this issue Mar 8, 2019 · 0 comments
Open

Bug in setindex #217

aaowens opened this issue Mar 8, 2019 · 0 comments

Comments

@aaowens
Copy link
Contributor

aaowens commented Mar 8, 2019

This works

using IndexedTables
cs = Columns(x=[1.2, 3.4], y=[3,4])
 t = table(cs, copy=false, pkey=:x)
ts = ndsparse(t)
ts[1.3] = (y = 5,)

However, if you first accidentally try to assign the wrong type, assigning correctly breaks the table.

julia> using IndexedTables

julia> cs = Columns(x=[1.2, 3.4], y=[3,4])
2-element StructArrays.StructArray{NamedTuple{(:x, :y),Tuple{Float64,Int64}},1,NamedTuple{(:x, :y),Tuple{Array{Float64,1},Array{Int64,1}}}}:
 (x = 1.2, y = 3)
 (x = 3.4, y = 4)

julia> t = table(cs, copy=false, pkey=:x)
Table with 2 rows, 2 columns:
x    y
──────
1.2  3
3.4  4

julia> ts = ndsparse(t)
1-d NDSparse with 2 values (1 field named tuples):
x   │ y
────┼──
1.2 │ 3
3.4 │ 4

julia> ts[1.3] = 5
ERROR: type Int64 has no field y
...

julia> ts
1-d NDSparse with 2 values (1 field named tuples):
x   │ y
────┼──
1.2 │ 3
3.4 │ 4
julia> ts[1.3] = (y = 5,)
(y = 5,)

julia> ts
Error showing value of type NDSparse{NamedTuple{(:y,),Tuple{Int64}},Tuple{Float64},StructArrays.StructArray{NamedTuple{(:x,),Tuple{Float64}},1,NamedTuple{(:x,),Tuple{Array{Float64,1}}}},StructArrays.StructArray{NamedTuple{(:y,),Tuple{Int64}},1,NamedTuple{(:y,),Tuple{Array{Int64,1}}}}}:
ERROR: index and data must have the same number of elements

I think this is because of this function

function _setindex_scalar!(t, rhs, idxs)
    push!(t.index_buffer, idxs)
    push!(t.data_buffer, rhs)
    t
end

It doesn't check the types beforehand, so it successfully pushes to the index but fails to push to the data.

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

1 participant