Repository: JuliaAI/MLJBase.jl (julia)

Issue:
Bug in display for one-dimensional range over functions
```julia
julia> range(Any, :f, values=[cos, sin, tan])
Error showing value of type NominalRange{Any, 3}:
ERROR: MethodError: Cannot `convert` an object of type typeof(sin) to an object of type typeof(cos)\
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:205
Stacktrace:
  [1] push!(a::Vector{typeof(cos)}, item::Function)
    @ Base ./array.jl:932
  [2] sequence_string(itr::Vector{Function}, n::Int64)
    @ MLJBase ~/MLJ/MLJBase/src/utilities.jl:250
  [3] sequence_string(itr::Vector{Function})
    @ MLJBase ~/MLJ/MLJBase/src/utilities.jl:235
  [4] show(stream::IOContext{Base.TTY}, r::NominalRange{Any, 3})
    @ MLJBase ~/MLJ/MLJBase/src/hyperparam/one_dimensional_ranges.jl:49
  [5] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, x::NominalRange{Any, 3})
    @ Base.Multimedia ./multimedia.jl:47
  [6] (::REPL.var"#38#39"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:220
  [7] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
  [8] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:213
  [9] display(d::REPL.REPLDisplay, x::Any)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:225
 [10] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
 [11] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [12] invokelatest
    @ ./essentials.jl:706 [inlined]
 [13] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:247
 [14] (::REPL.var"#40#41"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:231
 [15] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
 [16] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:229
 [17] (::REPL.var"#do_respond#61"{Bool, Bool, REPL.var"#72#82"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:798
 [18] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [19] invokelatest
    @ ./essentials.jl:706 [inlined]
 [20] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2441
 [21] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1126
 [22] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:411
```

Pull request:
resolves #667

Patch:
diff --git a/src/utilities.jl b/src/utilities.jl
index 98afc535..7109d034 100644
--- a/src/utilities.jl
+++ b/src/utilities.jl
@@ -226,7 +226,8 @@ end
 Return a "sequence" string from the first `n` elements generated
 by `itr`.
 
-    sequence_string(1:10, 3)
+    julia> MLJBase.sequence_string(1:10, 4)
+    "1, 2, 3, 4, ..."
 
 **Private method.**
 
@@ -238,7 +239,7 @@ function sequence_string(itr::Itr, n=3) where Itr
         I isa Base.HasShape ||
         I isa IsInfinite ||
         throw(Argumenterror("Unsupported iterator. "))
-    vals = typeof(first(itr))[]
+    vals = String[]
     i = 0
     earlystop = false
     for x in itr
@@ -247,7 +248,7 @@ function sequence_string(itr::Itr, n=3) where Itr
             earlystop = true
             break
         else
-            push!(vals, x)
+            push!(vals, string(x))
         end
     end
     ret = join(vals, ", ")


Test patch:
diff --git a/test/utilities.jl b/test/utilities.jl
index 77c87fff..0f356f01 100644
--- a/test/utilities.jl
+++ b/test/utilities.jl
@@ -134,6 +134,8 @@ end
     @test MLJBase.sequence_string(1:10) == "1, 2, 3, ..."
     @test MLJBase.sequence_string(1:3) == "1, 2, 3"
     @test MLJBase.sequence_string(1:2) == "1, 2"
+    @test MLJBase.sequence_string([sin, cos, tan, asin]) ==
+        "sin, cos, tan, ..."
 end
 
 end # module