You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
This works
However, if you first accidentally try to assign the wrong type, assigning correctly breaks the table.
I think this is because of this function
It doesn't check the types beforehand, so it successfully pushes to the index but fails to push to the data.
The text was updated successfully, but these errors were encountered: