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 displaying KeyedArray on nightly #159

Closed
kpobrien opened this issue Oct 29, 2024 · 6 comments · Fixed by #160
Closed

error displaying KeyedArray on nightly #159

kpobrien opened this issue Oct 29, 2024 · 6 comments · Fixed by #160

Comments

@kpobrien
Copy link
Contributor

Displaying a KeyedArray on nightly (on 2024-10-29, Development version 1.12.0-DEV.1514) results in the error below:

julia> using AxisKeys
julia> KeyedArray(rand(Float64,4), [:a, :b,:c,:d])
1-dimensional KeyedArray(...) with keys:
   4-element Vector{Symbol}
And data, 4-element Vector{Float64}:
 Error showing value of type KeyedArray{Float64, 1, Vector{Float64}, Base.RefValue{Vector{Symbol}}}:
ERROR: MethodError: no method matching iterate(::AxisKeys.ShowWith{Symbol, @NamedTuple{color::Symbol}})
The function `iterate` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  iterate(::AbstractString, ::Integer)
   @ Base strings/basic.jl:154
  iterate(::Core.MethodMatch, ::Int64)
   @ Base deprecated.jl:403
  iterate(::Core.MethodMatch)
   @ Base deprecated.jl:403
  ...

Stacktrace:
  [1] check_textwidth(str::AxisKeys.ShowWith{Symbol, @NamedTuple{color::Symbol}}, maxwidth::Int64)
    @ Base ./strings/util.jl:620
  [2] show(io::IOContext{…}, mime::MIME{…}, str::AxisKeys.ShowWith{…}; limit::Nothing)
    @ Base ./strings/io.jl:220
  [3] show
    @ ./strings/io.jl:204 [inlined]
  [4] show(io::IOContext{IOBuffer}, m::String, x::AxisKeys.ShowWith{Symbol, @NamedTuple{color::Symbol}})
    @ Base.Multimedia ./multimedia.jl:123
  [5] sprint(::Function, ::String, ::Vararg{Any}; context::IOContext{REPL.LimitIO{Base.TTY}}, sizehint::Int64)
    @ Base ./strings/io.jl:115
  [6] sprint
    @ ./strings/io.jl:110 [inlined]
  [7] print_matrix_row(io::IOContext{…}, X::AbstractVecOrMat, A::Vector{…}, i::Int64, cols::Vector{…}, sep::String, idxlast::Int64)
    @ Base ./arrayshow.jl:108
  [8] _print_matrix(io::IOContext{…}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{…}, colsA::UnitRange{…})
    @ Base ./arrayshow.jl:213
  [9] print_matrix
    @ ./arrayshow.jl:171 [inlined]
 [10] print_matrix(io::IOContext{REPL.LimitIO{Base.TTY}}, X::Matrix{Any})
    @ Base ./arrayshow.jl:171
 [11] keyed_print_matrix(io::IOContext{…}, A::KeyedArray{…}, reduce_size::Bool)
    @ AxisKeys ~/.julia/packages/AxisKeys/0waBN/src/show.jl:120
 [12] print_matrix
    @ ~/.julia/packages/AxisKeys/0waBN/src/show.jl:76 [inlined]
 [13] print_array
    @ ./arrayshow.jl:358 [inlined]
 [14] show(io::IOContext{…}, ::MIME{…}, X::KeyedArray{…})
    @ Base ./arrayshow.jl:399
 [15] show_repl(io::IO, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:575
 [16] show_limited(io::IO, mime::MIME, x::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:544
 [17] (::REPL.var"#display##0#display##1"{REPL.REPLDisplay{}, MIME{}, Base.RefValue{}})(io::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:567
 [18] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:868
 [19] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:553
 [20] display
    @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:573 [inlined]
 [21] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [22] #invokelatest#1
    @ ./essentials.jl:1049 [inlined]
 [23] invokelatest
    @ ./essentials.jl:1046 [inlined]
 [24] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{…})
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:616
 [25] (::REPL.var"#print_response##0#print_response##1"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:585
 [26] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:868
 [27] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:583
 [28] (::REPL.var"#do_respond#71"{})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:1210
 [29] #invokelatest#1
    @ ./essentials.jl:1049 [inlined]
 [30] invokelatest
    @ ./essentials.jl:1046 [inlined]
 [31] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:2772
 [32] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:1681
 [33] (::REPL.var"#59#60"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/REPL/src/REPL.jl:687
Some type information was truncated. Use `show(err)` to see complete types.

We can confirm the error results from the display command not print, or show:

julia> @show(KeyedArray(rand(Float64,4), [:a, :b,:c,:d]));
KeyedArray(rand(Float64, 4), [:a, :b, :c, :d]) = [0.27586215985934537, 0.5181992461296931, 0.19427963695732176, 0.9674828879385414]

julia> show(KeyedArray(rand(Float64,4), [:a, :b,:c,:d]))
[0.9295321780764085, 0.961158616088421, 0.4734082404063982, 0.6292398438676412]
julia> println(KeyedArray(rand(Float64,4), [:a, :b,:c,:d]));
[0.2086448361209724, 0.02823152855362432, 0.956823811051792, 0.04670516757378518]

julia> display(KeyedArray(rand(Float64,4), [:a, :b,:c,:d]));
1-dimensional KeyedArray(...) with keys:
   4-element Vector{Symbol}
And data, 4-element Vector{Float64}:
 ERROR: MethodError: no method matching iterate(::AxisKeys.ShowWith{Symbol, @NamedTuple{color::Symbol}})

Executing the same command while suppressing displaying does not give an error:

julia> KeyedArray(rand(Float64,4), [:a, :b,:c,:d]);

and executing the first command on Julia 1.11.1 displays the KeyedArray as expected:

julia> using AxisKeys
julia> KeyedArray(rand(Float64,4), [:a, :b,:c,:d])
1-dimensional KeyedArray(...) with keys:
   4-element Vector{Symbol}
And data, 4-element Vector{Float64}:
 (:a)  0.09950665556594684
 (:b)  0.9211918930215249
 (:c)  0.2873636769512212
 (:d)  0.7485715407624418
@aplavin
Copy link
Collaborator

aplavin commented Oct 29, 2024

Seems like Julia nightly assumes that all AbstractStrings support iterate(), which isn't mentioned at all in the AbstractString docs... Probably an unintended breaking change there?

@mcabbott
Copy link
Owner

In case it helps narrowing things down, I don't see this on Version 1.12.0-DEV.1375 (2024-10-14) Commit 9e92a9d174 (15 days old master) -- which also does not have a Base.check_textwidth.

I believe print_matrix used to have its alignment easily thrown off by colour codes / unicode, and possibly the whole reason to define ShowWith was to work around such bugs? If so, the ideal solution might be to rip things out.

Defining iterate might be another way of course.

@kpobrien
Copy link
Contributor Author

To possibly help narrow it down further I tested many of the recent nightly versions. It starts to error around PR#56324 Version 1.12.0-DEV.1494 (2024-10-25) although I can't imagine how that documentation PR would be responsible.

can't test
 inference: don't add backdge when applicable inferred to return Bool #56316 
https://github.com/JuliaLang/julia/pull/56316

works
support isless for zero-dimensional AbstractArrays (#55772)
https://github.com/JuliaLang/julia/commit/b38fde1ad42c977878d4f481c962b108a3ae20ab
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1205 (2024-09-14)
 _/ |\__'_|_|_|\__'_|  |  nsajko:isless_zerodim_AbstractArray/23c282009c2 (fork: 2 commits, 45 days)

works
julia +pr55776  
Fix unsafe_read for IOBuffer with non dense data (#55776)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1209 (2024-09-15)
 _/ |\__'_|_|_|\__'_|  |  nhz2:nz/io-buffer-read-fixes/2450f2c9270 (fork: 4 commits, 45 days)

works
julia +pr56196
 Mark require_one_based_indexing and has_offset_axes as public (#5… 
https://github.com/JuliaLang/julia/commit/b81e33fe522f8a8f060f885f83944f11192cd0db
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1403 (2024-10-21)
 _/ |\__'_|_|_|\__'_|  |  adrhill:ah/public-require-one-based/24a64d34e2c (fork: 4 commits, 13 days)

works
julia +pr56243
 LinearAlgebra: replace some hardcoded loop ranges with axes (#56243) 
https://github.com/JuliaLang/julia/commit/ac5bb668dafbfb0ce96449cfa32e64821a4cce15
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1440 (2024-10-24)
 _/ |\__'_|_|_|\__'_|  |  jishnub/eachindex/208429dfa3f (fork: 4 commits, 10 days)

works
julia +pr54457
Make String(::Memory) copy (#54457)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1452 (2024-10-19)
 _/ |\__'_|_|_|\__'_|  |  nhz2:nz/fix-String-of-Memory/dd6a66a7a95 (fork: 16 commits, 10 days)

works
julia +pr56291
drop require lock when not needed during loading to allow parallel precompile loading (#56291)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1464 (2024-10-22)
 _/ |\__'_|_|_|\__'_|  |  jn/parallel-require-loading/c05e8f63587 (fork: 1 commits, 7 days)

works
inference: don't allow SSAValues in assignment lhs #56314 
https://github.com/JuliaLang/julia/pull/56314
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1480 (2024-10-24)
 _/ |\__'_|_|_|\__'_|  |  avi/minor-correction-typeinf_local/b7fb705a1b3 (fork: 1 commits, 5 days)

works
https://github.com/JuliaLang/julia/pull/56319
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1481 (2024-10-24)
 _/ |\__'_|_|_|\__'_|  |  lgoettgens:lg/header-jl_gc_new_weakref/1cac29acadf (fork: 2 commits, 5 days)

works
Avoid some allocations in various println methods (#56308)
https://github.com/JuliaLang/julia/pull/56308
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1483 (2024-10-24)
 _/ |\__'_|_|_|\__'_|  |  PallHaraldsson:patch-26/98100014672 (fork: 5 commits, 5 days)

works
julia +pr56310
https://github.com/JuliaLang/julia/pull/56310
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1486 (2024-10-24)
 _/ |\__'_|_|_|\__'_|  |  avi/fix-atomic-modify-tfunc/2900ccae223 (fork: 2 commits, 5 days)

errors
julia +pr56324
Add a developer documentation section to the LinearAlgebra docs #56324 
https://github.com/JuliaLang/julia/pull/56324
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1494 (2024-10-25)
 _/ |\__'_|_|_|\__'_|  |  jishnub/linalg_docs/b83720363a9 (fork: 1 commits, 4 days)

errors
julia +pr56322
DRAFT: REPL: know when to release the prefix context when completing #56322 
https://github.com/JuliaLang/julia/pull/56322
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1499 (2024-10-25)
 _/ |\__'_|_|_|\__'_|  |  IanButterworth:ib/repl_completion_release_prefix_context/6073643bc26 (fork: 1 commits, 4 days)

errors
julia +pr56336
🤖 [master] Bump the Pkg stdlib from 799dc2d54 to 116ba910c (#56336)
https://github.com/JuliaLang/julia/pull/56336
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1500 (2024-10-25)
 _/ |\__'_|_|_|\__'_|  |  DilumAluthgeBot:BumpStdlibs/Pkg-116ba910c-master/8a642878bcb (fork: 1 commits, 4 days)

errors
Wall-time/all tasks profiler (#55889)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1500 (2024-10-25)
 _/ |\__'_|_|_|\__'_|  |  dcn-all-task-profiler/e0213ebbf55 (fork: 1 commits, 4 days)

errors
julia +pr56223
Make LinearAlgebra.haszero public (#56223)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1501 (2024-10-25)
 _/ |\__'_|_|_|\__'_|  |  jishnub/haszero/cb093b183e0 (fork: 4 commits, 4 days)

errors
julia +pr56223
loading: clean up more concurrency issues #56329 
https://github.com/JuliaLang/julia/pull/56329
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1501 (2024-10-25)
 _/ |\__'_|_|_|\__'_|  |  jn/require-init/18462cda087 (fork: 1 commits, 4 days)

errors
julia +pr56330
Add one-arg norm method (#56330)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1502 (2024-10-27)
 _/ |\__'_|_|_|\__'_|  |  jishnub/norm_onearg/1f8276821d8 (fork: 5 commits, 4 days)

errors
julia  +pr56348
Change some hardcoded loop ranges to axes in dense linalg functions (#56348)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1503 (2024-10-26)
 _/ |\__'_|_|_|\__'_|  |  jishnub/dense_axes/8c759e813d7 (fork: 1 commits, 3 days)

errors
julia +pr56311
Fix log_quasitriu for internal scaling s=0 (#56311)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1509 (2024-10-28)
 _/ |\__'_|_|_|\__'_|  |  aravindh-krishnamoorthy:expm-logm-54833/2acb0623a3c (fork: 4 commits, 2 days)

works
julia +pr56320   
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1510 (2024-10-28)
 _/ |\__'_|_|_|\__'_|  |  RelationalAI:npr-pv-cpu-task-timer/2ad9bf6a439 (fork: 26 commits, 5 days)

errors
julia +pr42080
recommend explicit using Foo: Foo, ... in package code (was: "using considered harmful") (#42080)
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1513 (2024-10-25)
 _/ |\__'_|_|_|\__'_|  |  kc/warn_using/8b4ae86085f (fork: 13 commits, 4 days)

@kpobrien
Copy link
Contributor Author

I don't know whether it's better to get rid of ShowWith, define iterate or other options, but I tried defining iterate as Base.iterate(x::AxisKeys.ShowWith,i::Int=firstindex(string(x.val))) = iterate(string(x.val),i)and it seems to work on the latest nightly for my example and the example in the README:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.12.0-DEV.1514 (2024-10-29)
 _/ |\__'_|_|_|\__'_|  |  Commit e4dc9d357a1 (0 days old master)
|__/                   |

julia> using AxisKeys

julia> Base.iterate(x::AxisKeys.ShowWith,i::Int=firstindex(string(x.val))) = iterate(string(x.val),i)

julia> KeyedArray(rand(Float64,4), [:a, :b,:c,:d])
1-dimensional KeyedArray(...) with keys:
↓   4-element Vector{Symbol}
And data, 4-element Vector{Float64}:
 (:a)  0.18174911986946463
 (:b)  0.10323012297312506
 (:c)  0.49337807286356516
 (:d)  0.985614429657665

julia> using AxisKeys

julia> data = rand(Int8, 2,10,3) .|> abs;

julia> A = KeyedArray(data; channel=[:left, :right], time=range(13, step=2.5, length=10), iter=31:33)
3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   channel ∈ 2-element Vector{Symbol}
→   time ∈ 10-element StepRangeLen{Float64,...}
◪   iter ∈ 3-element UnitRange{Int64}
And data, 2×10×3 Array{Int8, 3}:
[:, :, 1] ~ (:, :, 31):
            (13.0)  (15.5)  (18.0)  (20.5)  …  (28.0)  (30.5)  (33.0)  (35.5)
  (:left)     55      29      20      74        102      39      38      82
  (:right)   122      52      79      94        114     101     124     110

[:, :, 2] ~ (:, :, 32):
            (13.0)  (15.5)  (18.0)  (20.5)  …  (28.0)  (30.5)  (33.0)  (35.5)
  (:left)     42     120       6      20         48      25      45      43
  (:right)   101      63      50      22        121      69      72     111

[:, :, 3] ~ (:, :, 33):
            (13.0)  (15.5)  (18.0)  (20.5)  …  (28.0)  (30.5)  (33.0)  (35.5)
  (:left)     92     119      75       1         40     104      37      36
  (:right)    13     126      58      78         34      82     110      56

julia> 

@aplavin
Copy link
Collaborator

aplavin commented Oct 30, 2024

I think you can even do iterate(...) = nothing, as it'll use show(::ShowWith) anyways.

@kpobrien
Copy link
Contributor Author

Good call, defining Base.iterate(x::AxisKeys.ShowWith) = nothing works.

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

Successfully merging a pull request may close this issue.

3 participants