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
It can't push its guess into the existing array, since convert(String, 3) is an error. It can't save vcat(A.index, 3) into the original object, as this has the wrong type.
It could make a better guess for strings (but what?) but there will always be stranger types for which it can't make a good guess. Maybe more cases should be made errors?
julia> A =KeyedArray(rand(Int8, 2); index=["a", "b"]);
julia>push!(A, "c"=>55); # given key has suitable type
julia> A
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:↓ index ∈3-element Vector{String}
And data, 3-element Vector{Int8}:
("a") -25
("b") -64
("c") 55
julia>push!(A, 3=>55);
ERROR: MethodError: no method matching String(::Int64)
julia> C =KeyedArray(rand(Int8, 2); index='a':'b');
julia>push!(C, 55); # it can guess the next key
julia> C # immutable C.index has been replaced1-dimensional KeyedArray(NamedDimsArray(...)) with keys:↓ index ∈3-element StepRange{Char,...}
And data, 3-element Vector{Int8}:
('a') 54
('b') 88
('c') 55
mcabbott
changed the title
push! doesn't work correctlypush! can leave the original array in a broken state
Jan 16, 2022
This seems fine:
but:
The text was updated successfully, but these errors were encountered: