rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
280 stars 41 forks source link

`show` fails on nested arrays #486

Closed rafaqz closed 9 months ago

rafaqz commented 1 year ago

E.g. in DynamicGrids.jl where the sim is a AbstractDimArray of matricies along a time dimension, show fails with:

julia> output = ArrayOutput(init; tspan=1:2)
2-element ArrayOutput{Matrix{Int64},1} with dimensions: 
  Ti Sampled{Int64} 1:2 ForwardOrdered Regular Intervals
 1  Error showing value of type ArrayOutput{Matrix{Int64}, Vector{Matrix{Int64}}, Extent{Matrix{Int64}, Nothin
g, Nothing, Int64}}:
ERROR: MethodError: no method matching String(::Matrix{Int64})

Closest candidates are:
  String(::String)
   @ Core boot.jl:360
  String(::Core.Compiler.LazyString)
   @ Core strings/lazy.jl:80
  String(::LazyString)
   @ Base strings/lazy.jl:80
  ...

Stacktrace:
  [1] iterate(::DimensionalData.ShowWith)
    @ DimensionalData ~/.julia/dev/DimensionalData/src/array/show.jl:144
  [2] Stateful
    @ ./iterators.jl:1407 [inlined]
  [3] escape_string(io::IOContext{IOBuffer}, s::DimensionalData.ShowWith, esc::Tuple{Char, Char}; keep::Tuple{
})
    @ Base ./strings/io.jl:403
  [4] escape_string
    @ ./strings/io.jl:402 [inlined]
  [5] print_quoted
    @ ./strings/io.jl:436 [inlined]
  [6] show(io::IOContext{IOBuffer}, s::DimensionalData.ShowWith)
    @ Base ./strings/io.jl:193
  [7] sprint(f::Function, args::DimensionalData.ShowWith; context::IOContext{Base.TTY}, sizehint::Int64)
    @ Base ./strings/io.jl:112
  [8] print_matrix_row(io::IOContext{Base.TTY}, X::AbstractVecOrMat, A::Vector{Tuple{Int64, Int64}}, i::Int64,
 cols::Vector{Int64}, sep::String, idxlast::Int64)
    @ Base ./arrayshow.jl:112
  [9] _print_matrix(io::IOContext{Base.TTY}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdot
s::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{Int64}, colsA::UnitRange{I
nt64})
    @ Base ./arrayshow.jl:213
 [10] print_matrix(io::IOContext{Base.TTY}, X::Matrix{DimensionalData.ShowWith}, pre::String, sep::String, pos
t::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64)
    @ Base ./arrayshow.jl:171
 [11] print_matrix
    @ ./arrayshow.jl:171 [inlined]
 [12] _print_matrix(io::IOContext{Base.TTY}, A::Vector{Matrix{Int64}}, lookups::Tuple{DimensionalData.Dimensio
ns.LookupArrays.Sampled{Int64, UnitRange{Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, Dimen
sionalData.Dimensions.LookupArrays.Regular{Int64}, DimensionalData.Dimensions.LookupArrays.Intervals{Dimension
alData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.NoMetadata}})
    @ DimensionalData ~/.julia/dev/DimensionalData/src/array/show.jl:88
 [13] print_matrix(io::IOContext{Base.TTY}, A::ArrayOutput{Matrix{Int64}, Vector{Matrix{Int64}}, Extent{Matrix
{Int64}, Nothing, Nothing, Int64}})
    @ DimensionalData ~/.julia/dev/DimensionalData/src/array/show.jl:76
 [14] print_array
    @ ~/.julia/packages/DimensionalData/pS9IE/src/array/show.jl:43 [inlined]
 [15] show_after
    @ ~/.julia/packages/DimensionalData/pS9IE/src/array/show.jl:35 [inlined]
 [16] show(io::IOContext{Base.TTY}, mime::MIME{Symbol("text/plain")}, A::ArrayOutput{Matrix{Int64}, Vector{Mat
rix{Int64}}, Extent{Matrix{Int64}, Nothing, Nothing, Int64}})
    @ DimensionalData ~/.julia/dev/DimensionalData/src/array/show.jl:27
 [17] (::REPL.var"#55#56"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}}
)(io::Any)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:274
 [18] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:555
 [19] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:262
 [20] display
    @ /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:279 [inlined]
 [21] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [22] #invokelatest#2
    @ ./essentials.jl:816 [inlined]
 [23] invokelatest
    @ ./essentials.jl:813 [inlined]
 [24] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothi
ng, AbstractDisplay})
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:303
 [25] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:285
 [26] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:555
 [27] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:283
 [28] (::REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, 
REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:897
 [29] #invokelatest#2
    @ ./essentials.jl:816 [inlined]
 [30] invokelatest
    @ ./essentials.jl:813 [inlined]
 [31] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.M
IState)
    @ REPL.LineEdit /opt/julia/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:2647
 [32] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL /opt/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:1298
 [33] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:514