mcabbott / mcabbott/AxisKeys.jl
Error trying to `show` KeyedArray with undef values
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 154
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
I ran into this when using wrapdims on a DataFrame which had a column containing vectors, leading wrapdims (which calls similar) to produce a KeyedArray with #undef values
Is wrapdims produce #undef values itself a bug or is that expected behaviour? I suppose expected behaviour and the default=... keyword must be used to avoid it?
Anyway, here's the error:
julia> df = DataFrame(r=1:100, c=1:100, v=fill([1], 100));
julia> AxisKeys.wrapdims(df, :v, :r, :c)
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓ r ∈ 100-element Vector{Int64}
→ c ∈ 100-element Vector{Int64}
And data, 100×100 Matrix{Vector{Int64}}:
Error showing value of type KeyedArray{Vector{Int64}, 2, NamedDimsArray{(:r, :c), Vector{Int64}, 2, Matrix{Vector{Int64}}}, Tuple{Vector{Int64}, Vector{Int64}}}:
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] getindex
@ ./array.jl:925 [inlined]
[2] macro expansion
@ ./multidimensional.jl:903 [inlined]
[3] macro expansion
@ ./cartesian.jl:64 [inlined]
[4] _unsafe_getindex!
@ ./multidimensional.jl:898 [inlined]
[5] _unsafe_getindex(::IndexLinear, ::Matrix{Vector{Int64}}, ::UnitRange{Int64}, ::UnitRange{Int64})
@ Base ./multidimensional.jl:889
[6] _getindex
@ ./multidimensional.jl:875 [inlined]
[7] getindex
@ ./abstractarray.jl:1236 [inlined]
[8] keyed_print_matrix(io::IOContext{Base.TTY}, A::KeyedArray{Vector{Int64}, 2, NamedDimsArray{(:r, :c), Vector{Int64}, 2, Matrix{Vector{Int64}}}, Tuple{Vector{Int64}, Vector{Int64}}}, reduce_size::Bool)
@ AxisKeys ~/.julia/packages/AxisKeys/MK99E/src/show.jl:101
[9] print_matrix
@ ~/.julia/packages/AxisKeys/MK99E/src/show.jl:77 [inlined]
[10] print_array
@ ./arrayshow.jl:358 [inlined]
[11] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, X::KeyedArray{Vector{Int64}, 2, NamedDimsArray{(:r, :c), Vector{Int64}, 2, Matrix{Vector{Int64}}}, Tuple{Vector{Int64}, Vector{Int64}}})
@ Base ./arrayshow.jl:399
[12] (::REPL.var"#43#44"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:267
[13] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:521
[14] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:260
[15] display(d::REPL.REPLDisplay, x::Any)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:272
[16] display(x::Any)
@ Base.Multimedia ./multimedia.jl:328
[17] #invokelatest#2
@ ./essentials.jl:729 [inlined]
[18] invokelatest
@ ./essentials.jl:726 [inlined]
[19] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:296
[20] (::REPL.var"#45#46"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:278
[21] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:521
[22] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:276
[23] (::REPL.var"#do_respond#66"{Bool, Bool, REPL.var"#77#87"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:857
[24] #invokelatest#2
@ ./essentials.jl:729 [inlined]
[25] invokelatest
@ ./essentials.jl:726 [inlined]
[26] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
@ REPL.LineEdit /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2510
[27] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
@ REPL /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/REPL/src/REPL.jl:1248
[28] (::REPL.var"#49#54"{REPL.LineEditREPL, REPL.REPLBackendRef})()
@ REPL ./task.jl:484
The error seems to be triggered only by the plain-text show:
julia> arr = similar(KeyedArray(fill([1], 2, 3); a=1:2, b=1:3));
julia> show(stdout, arr)
[#undef #undef #undef; #undef #undef #undef]
julia> show(stdout, MIME("text/plain"), arr)
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓ a ∈ 2-element UnitRange{Int64}
→ b ∈ 3-element UnitRange{Int64}
And data, 2×3 Matrix{Vector{Int64}}:
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] getindex
@ ./array.jl:925 [inlined]
[2] macro expansion
@ ./multidimensional.jl:903 [inlined]
[3] macro expansion
@ ./cartesian.jl:64 [inlined]
[4] _unsafe_getindex!
@ ./multidimensional.jl:898 [inlined]
[5] _unsafe_getindex(::IndexLinear, ::Matrix{Vector{Int64}}, ::Base.Slice{Base.OneTo{Int64}}, ::Base.Slice{Base.OneTo{Int64}})
@ Base ./multidimensional.jl:889
[6] _getindex
@ ./multidimensional.jl:875 [inlined]
[7] getindex
@ ./abstractarray.jl:1236 [inlined]
[8] keyed_print_matrix(io::IOContext{Base.TTY}, A::KeyedArray{Vector{Int64}, 2, NamedDimsArray{(:a, :b), Vector{Int64}, 2, Matrix{Vector{Int64}}}, Tuple{UnitRange{Int64}, UnitRange{Int64}}}, reduce_size::Bool)
@ AxisKeys ~/.julia/packages/AxisKeys/MK99E/src/show.jl:101
[9] print_matrix
@ ~/.julia/packages/AxisKeys/MK99E/src/show.jl:77 [inlined]
[10] print_array
@ ./arrayshow.jl:358 [inlined]
[11] show(io::Base.TTY, #unused#::MIME{Symbol("text/plain")}, X::KeyedArray{Vector{Int64}, 2, NamedDimsArray{(:a, :b), Vector{Int64}, 2, Matrix{Vector{Int64}}}, Tuple{UnitRange{Int64}, UnitRange{Int64}}})
@ Base ./arrayshow.jl:399
[12] top-level scope
@ REPL[64]:1
by the look of it, due to keyed_print_matrix not checking isassigned?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the similar(KeyedArray(...)) example and compare plain show with MIME("text/plain"). Inspect show.jl, especially keyed_print_matrix around line 101, where the stack trace points. Done means displaying a KeyedArray containing unassigned values no longer raises UndefRefError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100