NamedArrays.jl
NamedArrays.jl copied to clipboard
n[1:end] doesn't work for matrices with Symbol names
Here's an example:
julia> a = [1 3; 2 4];
julia> a[1:end]
4-element Vector{Int64}:
1
2
3
4
julia> n = NamedArray(a, ([:a, :b], [:c, :d]));
julia> n[1:end]
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Symbol
Stacktrace
Stacktrace:
[1] convert
@ ~/.julia/packages/OrderedCollections/vTcqn/src/ordered_dict.jl:106 [inlined]
[2] setindex!
@ ./array.jl:969 [inlined]
[3] similar(n::NamedMatrix{Int64, Matrix{Int64}, Tuple{OrderedCollections.OrderedDict{Symbol, Int64}, OrderedCollections.OrderedDict{Symbol, Int64}}}, t::Type, dims::Tuple{Int64})
@ NamedArrays ~/.julia/packages/NamedArrays/spYk1/src/base.jl:45
[4] similar
@ ./abstractarray.jl:836 [inlined]
[5] _unsafe_getindex
@ ./multidimensional.jl:873 [inlined]
[6] _getindex
@ ./multidimensional.jl:861 [inlined]
[7] getindex(A::NamedMatrix{Int64, Matrix{Int64}, Tuple{OrderedCollections.OrderedDict{Symbol, Int64}, OrderedCollections.OrderedDict{Symbol, Int64}}}, I::UnitRange{Int64})
@ Base ./abstractarray.jl:1294
[8] top-level scope
@ REPL[5]:1
Thanks for finding this bug, for some reason it has to do with the type of the names being Symbol, which seems to be an edge case of some sort.