IndexedTables.jl
IndexedTables.jl copied to clipboard
Not possible to edit or add rows on a NDSparse table
I am unable to edit or add rows in a NDSparce table. Is it by design or a bug ?
I can "edit" the table, but it seems it doesn't produce any effect on the table itself.
julia> myTable = ndsparse((
region = ["US","US","US","US","EU","EU","EU","EU"],
product = ["apple","apple","banana","banana","apple","apple","banana","banana"],
year = [2011,2010,2011,2010,2011,2010,2011,2010]
),(
production = [3.3,3.2,2.3,2.1,2.7,2.8,1.5,1.3],
consumption = [4.3,7.4,2.5,9.8,3.2,4.3,6.5,3.0]
))
3-d NDSparse with 8 values (2 field named tuples):
region product year │ production consumption
───────────────────────┼────────────────────────
"EU" "apple" 2010 │ 2.8 4.3
"EU" "apple" 2011 │ 2.7 3.2
"EU" "banana" 2010 │ 1.3 3.0
"EU" "banana" 2011 │ 1.5 6.5
"US" "apple" 2010 │ 3.2 7.4
"US" "apple" 2011 │ 3.3 4.3
"US" "banana" 2010 │ 2.1 9.8
"US" "banana" 2011 │ 2.3 2.5
julia> myTable["EU","banana","2011"] = (2.5, 7.5)
(2.5, 7.5)
julia> myTable["EU","banana","2012"] = (2.5, 7.5)
(2.5, 7.5)
julia> flush!(myTable)
julia> myTable
3-d NDSparse with 8 values (2 field named tuples):
region product year │ production consumption
───────────────────────┼────────────────────────
"EU" "apple" 2010 │ 2.8 4.3
"EU" "apple" 2011 │ 2.7 3.2
"EU" "banana" 2010 │ 1.3 3.0
"EU" "banana" 2011 │ 1.5 6.5
"US" "apple" 2010 │ 3.2 7.4
"US" "apple" 2011 │ 3.3 4.3
"US" "banana" 2010 │ 2.1 9.8
"US" "banana" 2011 │ 2.3 2.5
The year field in your key is an integer value, not a string. It will work if you remove the quotation marks around 2011 and 2012 when editing and adding entries.
Should this have thrown an error though?