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

DictTable: insert! and delete! don't work with named index column #112

Open
tkemmer opened this issue Sep 26, 2023 · 0 comments
Open

DictTable: insert! and delete! don't work with named index column #112

tkemmer opened this issue Sep 26, 2023 · 0 comments

Comments

@tkemmer
Copy link

tkemmer commented Sep 26, 2023

Adding/removing rows to/from DictTables only seems to work when the index column does not have a name, e.g., when the table is constructed from dictionaries:

julia> idx = [1, 2, 3]; dt = DictTable(name = Dictionary(idx, ["A", "B", "C"]))
DictTable with 1 column and 3 rows:
     name
   ┌─────
 1 │ A
 2 │ B
 3 │ C

julia> delete!(dt, 1)
DictTable with 1 column and 2 rows:
     name
   ┌─────
 2 │ B
 3 │ C

julia> insert!(dt, 4, (name = "D",))
DictTable with 1 column and 3 rows:
     name
   ┌─────
 2 │ B
 3 │ C
 4 │ D

However, when creating a DictTable with a named index column, insert! and delete! throw errors:

julia> dt = DictTable(idx = [1, 2, 3], name = ["A", "B", "C"])
DictTable with 1 column and 3 rows:
 idx   name
 ────┬─────
 1   │ A
 2   │ B
 3   │ C

julia> delete!(dt, 1)
ERROR: TypeError: in Tokenized, in Parent, expected Parent<:AbstractDictionary, got Type{Int64}
Stacktrace:
 [1] tokenized(d::Indices{Int64})
   @ Dictionaries ~/.julia/packages/Dictionaries/7aBxp/src/tokens.jl:146
 [2] map
   @ ./tuple.jl:274 [inlined]
 [3] map(::Function, ::NamedTuple{(:idx, :name), Tuple{Indices{Int64}, Dictionary{Int64, String}}})
   @ Base ./namedtuple.jl:219
 [4] deletetoken!(d::DictTable{Int64, NamedTuple{(:idx, :name), Tuple{Int64, String}}, NamedTuple{(:idx, :name), Tuple{Indices{Int64}, Dictionary{Int64, String}}}, Indices{Int64}}, t::Tuple{Int64, Int64})
   @ TypedTables ~/.julia/packages/TypedTables/4OVef/src/DictTable.jl:170
 [5] delete!(d::DictTable{Int64, NamedTuple{(:idx, :name), Tuple{Int64, String}}, NamedTuple{(:idx, :name), Tuple{Indices{Int64}, Dictionary{Int64, String}}}, Indices{Int64}}, i::Int64)
   @ Dictionaries ~/.julia/packages/Dictionaries/7aBxp/src/insertion.jl:293
 [6] top-level scope
   @ REPL[86]:1

julia> insert!(dt, 4, (idx = 4, name = "D"))
ERROR: TypeError: in Tokenized, in Parent, expected Parent<:AbstractDictionary, got Type{Int64}
Stacktrace:
 [1] tokenized(d::Indices{Int64})
   @ Dictionaries ~/.julia/packages/Dictionaries/7aBxp/src/tokens.jl:146
 [2] map
   @ ./tuple.jl:274 [inlined]
 [3] map(::Function, ::NamedTuple{(:idx, :name), Tuple{Indices{Int64}, Dictionary{Int64, String}}})
   @ Base ./namedtuple.jl:219
 [4] gettoken!(d::DictTable{Int64, NamedTuple{(:idx, :name), Tuple{Int64, String}}, NamedTuple{(:idx, :name), Tuple{Indices{Int64}, Dictionary{Int64, String}}}, Indices{Int64}}, i::Int64)
   @ TypedTables ~/.julia/packages/TypedTables/4OVef/src/DictTable.jl:166
 [5] insert!(d::DictTable{Int64, NamedTuple{(:idx, :name), Tuple{Int64, String}}, NamedTuple{(:idx, :name), Tuple{Indices{Int64}, Dictionary{Int64, String}}}, Indices{Int64}}, i::Int64, value::NamedTuple{(:idx, :name), Tuple{Int64, String}})
   @ Dictionaries ~/.julia/packages/Dictionaries/7aBxp/src/insertion.jl:133
 [6] top-level scope
   @ REPL[87]:1

(Tested with Julia 1.9.3)

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