andyferris / Dictionaries.jl

An alternative interface for dictionaries in Julia, for improved productivity and performance
Other
282 stars 28 forks source link

Constructing a Dictionary from ranges #7

Closed yurivish closed 4 years ago

yurivish commented 4 years ago

Hello! I'm playing with this cool package on Christmas and happened upon an error.

The docstring for Dictionary says that it is possible to construct a Dictionary from two arbitrary Julia iterables:

Dictionary(indices, values)

  Construct a Dictionary <: AbstractDictionary from two arbitrary Julia iterables, one specifying the indices and one specifying the values. Lookup uses naive
  iteration.

It looks like right now you can indeed construct such a dictionary where the keys and/or values are given as a UnitRange, but then there's an error upon show:

julia> Dictionary([1,2,3], [4,5,6])
3-element Dictionary{Int64,Int64,Array{Int64,1},Array{Int64,1}}
 1 │ 4
 2 │ 5
 3 │ 6

julia> Dictionary(1:3, 4:6); # You can construct one, just not show it.

julia> Dictionary(1:3, 4:6)
3-element Dictionary{Int64,Int64,UnitRange{Int64},UnitRange{Int64}}Error showing value of type Dictionary{Int64,Int64,UnitRange{Int64},UnitRange{Int64}}:
ERROR: Every settable AbstractDictionary type must define a method for `isassigned`: Dictionary{Int64,Int64,UnitRange{Int64},UnitRange{Int64}}
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] isassigned(::Dictionary{Int64,Int64,UnitRange{Int64},UnitRange{Int64}}, ::Int64) at /Users/yurivish/.julia/packages/Dictionaries/mjUAn/src/AbstractDictionary.jl:260
 [3] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::Dictionary{Int64,Int64,UnitRange{Int64},UnitRange{Int64}}) at /Users/yurivish/.julia/packages/Dictionaries/mjUAn/src/show.jl:76
 [4] display(::REPL.REPLDisplay, ::MIME{Symbol("text/plain")}, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:132
 [5] display(::REPL.REPLDisplay, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:136
 [6] display(::Any) at ./multimedia.jl:323
 [7] #invokelatest#1 at ./essentials.jl:709 [inlined]
 [8] invokelatest at ./essentials.jl:708 [inlined]
 [9] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:156
 [10] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:141
 [11] (::REPL.var"#do_respond#38"{Bool,REPL.var"#48#57"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:719
 [12] #invokelatest#1 at ./essentials.jl:709 [inlined]
 [13] invokelatest at ./essentials.jl:708 [inlined]
 [14] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/LineEdit.jl:2306
 [15] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:1045
 [16] run_repl(::REPL.AbstractREPL, ::Any) at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:201
 [17] (::Base.var"#770#772"{Bool,Bool,Bool,Bool})(::Module) at ./client.jl:382
 [18] #invokelatest#1 at ./essentials.jl:709 [inlined]
 [19] invokelatest at ./essentials.jl:708 [inlined]
 [20] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:366
 [21] exec_options(::Base.JLOptions) at ./client.jl:304
 [22] _start() at ./client.jl:460
andyferris commented 4 years ago

@yurivish sorry for the delay, apparently I wasn't "watching" this github repo! Oops!

Thansk for the report, I'll fix this as a part of #13.

yurivish commented 4 years ago

Hah, this was definitely an issue from another time... Excellent, thanks for fixing it (and for creating this package, and pushing towards a common interface for the various collection types)!