-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
undesirable output when showing empty set in the REPL #45229
Comments
it's just how things are displayed: julia> []
Any[]
julia> [1]
1-element Vector{Int64}:
1 you should open an issue with DataStructures.jl if you think it's too verbose, probably no actionable item here. |
Could you elaborate a bit more? Why is it a good idea to display 0-entry collections differently from collections with one or more entries? |
It doesn't matter, as long as it's readable and not confusing. |
But in this case (specialized for SortedSet), it's not readable and it is confusing. Methods written for Can you tell me: what exactly is that big string that is in my original posting? What statement in Base produced that? |
thus my original suggestion: opening an issue in The solution to that is for |
I continue to think this should be fixed in Base. If functions associated with abstract classes in Base that needlessly cause problems for library writers, this somewhat defeats the purpose of even having abstract classes in Base. But in any case, do you know which statement in Base generated that very long string in my original post? This might inform me what needs to be done with SortedSet. |
Mabye update julia? julia v1.7.2 + DataStructures v0.18.12 julia> s = SortedSet{Int}([4,3,2,1])
SortedSet{Int64, Base.Order.ForwardOrdering} with 4 elements:
1
2
3
4
julia> s = SortedSet{Int}([])
SortedSet(Int64[],
Base.Order.ForwardOrdering())
julia> SortedSet{Int}(Any[])
SortedSet(Int64[],
Base.Order.ForwardOrdering())
julia> SortedSet{Int}([])
SortedSet(Int64[],
Base.Order.ForwardOrdering())
julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
(@v1.7) pkg> st
Status `C:\Users\woclass\.julia\environments\v1.7\Project.toml`
[6e4b80f9] BenchmarkTools v1.2.2
[864edb3b] DataStructures v0.18.12
[31a5f54b] Debugger v0.6.8
|
Here is additional backstory on this request. I am the original author and still the main maintainer of sorted container data structures. The bad behavior reported in my original post is not for the master branch of DataStructures.jl but rather for the version in pull request: JuliaCollections/DataStructures.jl#787. In fact, in this PR 787, I removed the In any case, it would be helpful if someone could tell me where in Base is the code that outputs an AbstractSet to the REPL. |
https://github.com/JuliaLang/julia/blob/master/base/show.jl#L148-L189 |
OK, thanks! This helped me get started. What I found is: there are several classes in Base derived from AbstractSet including BitSet, Set, KeySet, and IdSet. Of these, none relies on |
This is due to #35417. There we decided to prefer 2-argument, parseable output for empty collections, but maybe that's the wrong default for non-arrays. |
Just for further information: the big string printed out by julia> SortedSet{Int}()
SortedSet{Int64, Base.Order.ForwardOrdering}(DataStructures.BalancedTree23{Int64, Nothing, Base.Order.ForwardOrdering}(Base.Order.ForwardOrdering(), DataStructures.KDRec{Int64, Nothing}[DataStructures.KDRec{Int64, Nothing}(1, 191898512, nothing), DataStructures.KDRec{Int64, Nothing}(1, 191898640, nothing)], DataStructures.TreeNode{Int64}[DataStructures.TreeNode{Int64}(1, 2, 0, 0, 12, 13)], 1, 1, Int64[], Int64[], BitSet([1, 2]), [32, 4, 10999411245313], [32, 4, 10999411245313]))
julia> SortedSet{Int64, Base.Order.ForwardOrdering}(DataStructures.BalancedTree23{Int64, Nothing, Base.Order.ForwardOrdering}(Base.Order.ForwardOrdering(), DataStructures.KDRec{Int64, Nothing}[DataStructures.KDRec{Int64, Nothing}(1, 191898512, nothing), DataStructures.KDRec{Int64, Nothing}(1, 191898640, nothing)], DataStructures.TreeNode{Int64}[DataStructures.TreeNode{Int64}(1, 2, 0, 0, 12, 13)], 1, 1, Int64[], Int64[], BitSet([1, 2]), [32, 4, 10999411245313], [32, 4, 10999411245313]))
ERROR: MethodError: no method matching DataStructures.BalancedTree23{Int64, Nothing, Base.Order.ForwardOrdering}(::Base.Order.ForwardOrdering, ::Vector{DataStructures.KDRec{Int64, Nothing}}, ::Vector{DataStructures.TreeNode{Int64}}, ::Int64, ::Int64, ::Vector{Int64}, ::Vector{Int64}, ::BitSet, ::Vector{Int64}, ::Vector{Int64})
Closest candidates are:
DataStructures.BalancedTree23{K, D, Ord}(::Val{true}, ::Any, ::Ord, ::Bool) where {K, D, Ord<:Base.Order.Ordering} at c:\Users\vavasis\OneDrive - University of Waterloo\Julia_pkg_devdir\DataStructures.jl\src\balanced_tree.jl:989
DataStructures.BalancedTree23{K, D, Ord}(::Ord) where {K, D, Ord<:Base.Order.Ordering} at c:\Users\vavasis\OneDrive - University of Waterloo\Julia_pkg_devdir\DataStructures.jl\src\balanced_tree.jl:134
Stacktrace:
[1] top-level scope
@ REPL[7]:1 |
The development branch mentioned in my original post has now become the master branch for DataStructures.jl. So fixing the undesirable behavior reported in my original post is now slightly more pressing. |
I am currently working on
SortedSet
from the packageDataStructures.jl
. SortedSet does not have its own output routines; instead, it relies on the routines inherited fromAbstractSet
in Base. However, these routines have unexpected behavior for an empty set. (Julia 1.7.1 on Windows, see below). I confirmed that the REPL output for ordinarySet
is also inconsistent when the set is empty, but in the case of ordinarySet
the issue is less obvious.The text was updated successfully, but these errors were encountered: