Skip to content

show(var::OutputVar) errors if var.dims is empty #208

Closed
@nefrathenrici

Description

@nefrathenrici

I recently ran into this error with a fully averaged OutputVar without any dims.
I believe this happens due to this line:
max_length_dims = maximum(length(x) for (x, _) in var.dims)

julia> year_net_radiation
Attributes:
  short_name => rlut + rsut - rsdt
  long_name  => TOA Outgoing Longwave Radiation, average within 1 Month + TOA Outgoing Shortwave Radiation, average within 1 Month - TOA Incident Shortwave Radiation, average within 1 Month averaged over lat (-90.0 to 90.0degrees_north) averaged over lon (-180.0 to 180.0degrees_east) averaged over time (2.592e6 to 3.93984e7s)
Dimension attributes:
Data defined over:
Error showing value of type OutputVar{Vector{Float32}, Array{Float32, 0}, Any, Dict{Union{AbstractString, Symbol}, Any}}:
ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
  [1] _empty_reduce_error()
    @ Base ./reduce.jl:319
  [2] mapreduce_empty(f::Function, op::Base.BottomRF{typeof(max)}, T::Type)
    @ Base ./reduce.jl:321
  [3] reduce_empty(op::Base.MappingRF{ClimaAnalysis.Var.var"#119#122", Base.BottomRF{typeof(max)}}, ::Type{Pair{String, Vector{Float32}}})
    @ Base ./reduce.jl:358
  [4] reduce_empty_iter
    @ ./reduce.jl:381 [inlined]
  [5] reduce_empty_iter
    @ ./reduce.jl:380 [inlined]
  [6] foldl_impl
    @ ./reduce.jl:49 [inlined]
  [7] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
  [8] mapfoldl
    @ ./reduce.jl:175 [inlined]
  [9] mapreduce
    @ ./reduce.jl:307 [inlined]
 [10] maximum
    @ ./reduce.jl:761 [inlined]
 [11] show(io::IOContext{Base.TTY}, var::OutputVar{Vector{Float32}, Array{Float32, 0}, Any, Dict{Union{AbstractString, Symbol}, Any}})
    @ ClimaAnalysis.Var ~/.julia/packages/ClimaAnalysis/VYWLo/src/Var.jl:2001
 [12] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, x::OutputVar{Vector{Float32}, Array{Float32, 0}, Any, Dict{Union{AbstractString, Symbol}, Any}})
    @ Base.Multimedia ./multimedia.jl:47
 [13] (::REPL.var"#68#69"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:367
 [14] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:661
 [15] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:353
 [16] display
    @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:372 [inlined]
 [17] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [18] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
 [19] invokelatest
    @ ./essentials.jl:1052 [inlined]
 [20] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:409
 [21] (::REPL.var"#70#71"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:378
 [22] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:661
 [23] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:376
 [24] (::REPL.var"#do_respond#96"{Bool, Bool, REPL.var"#112#130"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1003
 [25] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
 [26] invokelatest
    @ ./essentials.jl:1052 [inlined]
 [27] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2755
 [28] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1474
 [29] (::REPL.var"#75#81"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:480

julia> year_net_radiation.data
0-dimensional Array{Float32, 0}:
16.61134

julia> year_net_radiation.dims
OrderedCollections.OrderedDict{String, Vector{Float32}}()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions