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

Error trying to show KeyedArray with undef values #118

Open
nickrobinson251 opened this issue Jul 28, 2022 · 0 comments
Open

Error trying to show KeyedArray with undef values #118

nickrobinson251 opened this issue Jul 28, 2022 · 0 comments

Comments

@nickrobinson251
Copy link

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?

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