Skip to content

Bug when using a DynamicQuantities.QuantityArray based on StepRangeLen as axis #178

Description

@BambOoxX

I stumbled upon this behavior while discovering AxisKeys capabilities when trying to create a KeyedArray using a DynamicQuantities.QuantityArray as time axis.

Here is a MWE

#] activate --temp
#] add DynamicQuantities
#] add AxisKeys

using DynamicQuantities
using AxisKeys


t = QuantityArray(range(1,step=0.1,length=10),u"s")
KeyedArray(rand(10,3); time = t, channels = string.(1:3))

# Note that collecting the range works fine
# KeyedArray(rand(10,3); time = collect(t), channels = string.(1:3))

This fails with

2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   time ∈ 10-element QuantityArray{Float64,...}
→   channels ∈ 3-element Vector{String}
And data, 10×3 Matrix{Float64}:
Error showing value of type KeyedArray{Float64, 2, NamedDimsArray{(:time, :channels), Float64, 2, Matrix{Float64}}, Tuple{QuantityArray{Float64, 1, Dimensions{FRInt32}, Quantity{Float64, Dimensions{FRInt32}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, Vector{String}}}:

SYSTEM (REPL): showing an error caused an error
ERROR: 1-element ExceptionStack:
MethodError: no method matching StepRangeLen{Float64, Base.TwicePrecision{…}, Base.TwicePrecision{…}, Int64}(::UndefInitializer, ::Tuple{Int64})
The type `StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  StepRangeLen{T, R, S, L}(::R, ::S, ::Integer, ::Integer) where {T, R, S, L}
   @ Base range.jl:509
  StepRangeLen{T, R, S, L}(::R, ::S, ::Integer) where {T, R, S, L}
   @ Base range.jl:509
  StepRangeLen{T, R, S, L}(::StepRangeLen{T, R, S, L}) where {T<:AbstractFloat, R<:Base.TwicePrecision, S<:Base.TwicePrecision, L}
   @ Base twiceprecision.jl:539
  ...

Stacktrace:
  [1] similar(::Type{StepRangeLen{Float64, Base.TwicePrecision{…}, Base.TwicePrecision{…}, Int64}}, dims::Tuple{Int64})
    @ Base .\abstractarray.jl:867
  [2] similar(::Type{StepRangeLen{…}}, shape::Tuple{Base.OneTo{…}})
    @ Base .\abstractarray.jl:866
  [3] similar(bc::Base.Broadcast.Broadcasted{…}, ::Type{…})
    @ DynamicQuantities D:\bamboo\.julia\packages\DynamicQuantities\AQfiw\src\arrays.jl:326
  [4] copy
    @ .\broadcast.jl:919 [inlined]
  [5] materialize
    @ .\broadcast.jl:894 [inlined]
  [6] keyed_print_matrix(io::IOContext{…}, A::KeyedArray{…}, reduce_size::Bool)
    @ AxisKeys D:\bamboo\.julia\packages\AxisKeys\a6h2b\src\show.jl:100
  [7] print_matrix(io::IOContext{REPL.LimitIO{…}}, A::KeyedArray{Float64, 2, NamedDimsArray{…}, Tuple{…}})
    @ AxisKeys D:\bamboo\.julia\packages\AxisKeys\a6h2b\src\show.jl:76
  [8] print_array(io::IOContext{REPL.LimitIO{…}}, X::KeyedArray{Float64, 2, NamedDimsArray{…}, Tuple{…}})
    @ Base .\arrayshow.jl:358
  [9] show(io::IOContext{…}, ::MIME{…}, X::KeyedArray{…})
    @ Base .\arrayshow.jl:363
 [10] show_repl(io::IO, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:548
 [11] show_limited(io::IO, mime::MIME, x::Any)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:517
 [12] (::REPL.var"#display##0#display##1"{REPL.REPLDisplay{…}, MIME{…}, Base.RefValue{…}})(io::Any)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:540
 [13] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:833
 [14] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:526
 [15] display
    @ D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:546 [inlined]
 [16] display(x::Any)
    @ Base.Multimedia .\multimedia.jl:340
 [17] (::REPL.var"#print_response##2#print_response##3")()
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:590
 [18] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:445
 [19] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:427
 [20] start_repl_backend
    @ D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:424 [inlined]
 [21] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:653
 [22] run_repl(repl::REPL.AbstractREPL, consumer::Any)
    @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:639
 [23] run_std_repl(REPL::Module, quiet::Bool, banner::Symbol, history_file::Bool)
    @ Base .\client.jl:478
 [24] run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool)
    @ Base .\client.jl:499
 [25] repl_main
    @ .\client.jl:586 [inlined]
 [26] _start()
    @ Base .\client.jl:561
Stacktrace:
 [1] print_response(errio::IO, response::Any, backend::Union{…}, show_value::Bool, have_color::Bool, specialdisplay::Union{…})
   @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:599
 [2] (::REPL.var"#print_response##0#print_response##1"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
   @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:558
 [3] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
   @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:833
 [4] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
   @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:556
 [5] (::REPL.var"#do_respond#73"{…})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
   @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:1192
 [6] run_interface(terminal::Base.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
   @ REPL.LineEdit D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\LineEdit.jl:2854
 [7] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
   @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:1651
 [8] (::REPL.var"#61#62"{REPL.LineEditREPL, REPL.REPLBackendRef})()
   @ REPL D:\bamboo\.julia\juliaup\julia-1.12.5+0.x64.w64.mingw32\share\julia\stdlib\v1.12\REPL\src\REPL.jl:650
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions