-
Notifications
You must be signed in to change notification settings - Fork 254
SortedDict construction tripped up by tuples and Any #239
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
Comments
Here are a few more constructor issues to get them in one place: Raw pairs: julia> using DataStructures
julia> Dict("a" => 1)
Dict{String,Int64} with 1 entry:
"a" => 1
julia> SortedDict("a" => 1)
ERROR: MethodError: DataStructures.SortedDict{K,D,Ord<:Base.Order.Ordering}(::Pair{String,Int64}) is ambiguous. Candidates:
(::Type{DataStructures.SortedDict}){K,D}(ps::Pair{K,D}...) at /Users/sean/.julia/v0.5/DataStructures/src/sorted_dict.jl:35
(::Type{DataStructures.SortedDict})(kv) at /Users/sean/.julia/v0.5/DataStructures/src/sorted_dict.jl:57 |
Someone already reported a problem like this, but I can't find the issue or PR right now. A temporary workaround is to use |
#168 adds a bunch of the needed constructors, and I updated it recently (did I push?). I forget now why I didn't ask for a review and merge. :-/ will try to take a look today. |
Thanks Kevin. I saw it handled at least some of the constructors I mentioned. |
There is still a remaining issue where the constructor unexpectedly returns an eltype of
whereas with Dict:
This is causing a minor problem that I can workaround by explicitly passing the types or by wrapping the contents with Dict or collect. Do you have any plans to address this? Thanks. |
A PR to address it would be welcome. |
I am the oriignal author of this code, but I do not know how to fix this. I'm not even sure it's possible without adding a lot of inefficient code. The basic issue is that generators do not return useful eltypes: julia> eltype(i for i=1:2)
Any So routines in Base like julia> a = Vector{Any}();
julia> push!(a,2);
julia> push!(a,3.3);
julia> a
2-element Array{Any,1}:
2
3.3
julia> collect(a[i] for i=1:1)
1-element Array{Int64,1}:
2
julia> collect(a[i] for i=1:2)
2-element Array{Real,1}:
2
3.3 This kind of incremental type expansion would be difficult for SortedSet and SortedDict because the containers need to insert the elements on the fly using the sort-ordering, which is presumably linked to the type. I suggest you use the simple workaround: |
Closed via #787 |
The text was updated successfully, but these errors were encountered: