How to add or edit values in an sparse indexed table ? From the documentation I understood that the NDSparse object itself is immutable but not the underlying data, so I “understand” why something like this doesn’t work, but I don’t know how to obtain a new table with the new data:
IndexedTables is fine. JuliaDB is a wrapper around IndexedTables and offers extra features.
I see that your IndexedTables is at 0.12.0. Please, update import Pkg; Pkg.@pkg_str("add IndexedTables#master") because version 0.12.1 had some changes to some constructors.
However when I try to insert a new row (e.g. myTable["EU","banana",2012] = (production = 2.5, consumption = 7.5)) it “seems” all fine, but when I try to print the table I get the error:
[UPDATE]
Sorry it works fine, I may not have restarted Julia after the update??? When the master will be released ?
[/UPDATE]
julia> myTable
Error showing value of type NDSparse{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},Tuple{String,String,Int64},StructArrays.StructArray{NamedTuple{(:region, :product, :year),Tuple{String,String,Int64}},1,NamedTuple{(:region, :product, :year),Tuple{Array{String,1},Array{String,1},Array{Int64,1}}},Int64},StructArrays.StructArray{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},1,NamedTuple{(:production, :consumption),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}}:
ERROR: index and data must have the same number of elements
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] #ndsparse#103(::Function, ::Bool, ::Nothing, ::Bool, ::Function, ::Val{:serial}, ::NamedTuple{(:region, :product, :year),Tuple{Array{String,1},Array{String,1},Array{Int64,1}}}, ::NamedTuple{(:production, :consumption),Tuple{Array{Float64,1},Array{Float64,1}}}) at /home/lobianco/.julia/packages/IndexedTables/iteNw/src/ndsparse.jl:80
[3] #ndsparse at ./none:0 [inlined]
[4] #ndsparse#102 at /home/lobianco/.julia/packages/IndexedTables/iteNw/src/ndsparse.jl:65 [inlined]
[5] #ndsparse at ./none:0 [inlined]
[6] #ndsparse#106 at /home/lobianco/.julia/packages/IndexedTables/iteNw/src/ndsparse.jl:112 [inlined]
[7] #ndsparse at ./none:0 [inlined]
[8] #ndsparse#107 at /home/lobianco/.julia/packages/IndexedTables/iteNw/src/ndsparse.jl:116 [inlined]
[9] #ndsparse at ./none:0 [inlined]
[10] #NDSparse#109 at /home/lobianco/.julia/packages/IndexedTables/iteNw/src/ndsparse.jl:123 [inlined]
[11] Type at ./none:0 [inlined]
[12] flush!(::NDSparse{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},Tuple{String,String,Int64},StructArrays.StructArray{NamedTuple{(:region, :product, :year),Tuple{String,String,Int64}},1,NamedTuple{(:region, :product, :year),Tuple{Array{String,1},Array{String,1},Array{Int64,1}}},Int64},StructArrays.StructArray{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},1,NamedTuple{(:production, :consumption),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}}) at /home/lobianco/.julia/packages/IndexedTables/iteNw/src/indexing.jl:230
[13] show(::IOContext{REPL.Terminals.TTYTerminal}, ::NDSparse{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},Tuple{String,String,Int64},StructArrays.StructArray{NamedTuple{(:region, :product, :year),Tuple{String,String,Int64}},1,NamedTuple{(:region, :product, :year),Tuple{Array{String,1},Array{String,1},Array{Int64,1}}},Int64},StructArrays.StructArray{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},1,NamedTuple{(:production, :consumption),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}}) at /home/lobianco/.julia/packages/IndexedTables/iteNw/src/ndsparse.jl:275
[14] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::NDSparse{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},Tuple{String,String,Int64},StructArrays.StructArray{NamedTuple{(:region, :product, :year),Tuple{String,String,Int64}},1,NamedTuple{(:region, :product, :year),Tuple{Array{String,1},Array{String,1},Array{Int64,1}}},Int64},StructArrays.StructArray{NamedTuple{(:production, :consumption),Tuple{Float64,Float64}},1,NamedTuple{(:production, :consumption),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}}) at ./sysimg.jl:194
[15] display(::REPL.REPLDisplay, ::MIME{Symbol("text/plain")}, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:131
[16] display(::REPL.REPLDisplay, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:135
[17] display(::Any) at ./multimedia.jl:287
[18] #invokelatest#1 at ./essentials.jl:742 [inlined]
[19] invokelatest at ./essentials.jl:741 [inlined]
[20] print_response(::IO, ::Any, ::Any, ::Bool, ::Bool, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:155
[21] print_response(::REPL.AbstractREPL, ::Any, ::Any, ::Bool, ::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:140
[22] (::getfield(REPL, Symbol("#do_respond#38")){Bool,getfield(Atom, Symbol("##172#173")),REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:714
[23] #invokelatest#1 at ./essentials.jl:742 [inlined]
[24] invokelatest at ./essentials.jl:741 [inlined]
[25] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:2273
[26] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:1035
[27] run_repl(::REPL.AbstractREPL, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:192
[28] (::getfield(Base, Symbol("##734#736")){Bool,Bool,Bool,Bool})(::Module) at ./client.jl:362
[29] #invokelatest#1 at ./essentials.jl:742 [inlined]
[30] invokelatest at ./essentials.jl:741 [inlined]
[31] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:346
[32] exec_options(::Base.JLOptions) at ./client.jl:284
[33] _start() at ./client.jl:436