Skip to content

Commit

Permalink
Remove convert method to OrderedDict
Browse files Browse the repository at this point in the history
The generic one in Julia stdlib does the job, except for the deprecation
warning shown when converting from an unordered dict (such as `Base.Dict`)
to an `OrderedDict{K,V}` type.

This avoids potential invalidations in packages. There also is no explanation
as to why it makes sense to forbids such conversions.
  • Loading branch information
fingolfin committed Nov 24, 2024
1 parent b3b1df9 commit 68349aa
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,6 @@ defined order (such as `OrderedDict` and `SortedDict`), and `false` otherwise.
isordered(::Type{T}) where {T<:AbstractDict} = false
isordered(::Type{T}) where {T<:OrderedDict} = true

# conversion between OrderedDict types
function convert(::Type{OrderedDict{K,V}}, d::AbstractDict) where {K,V}
d isa OrderedDict{K, V} && return d
if !isordered(typeof(d))
Base.depwarn("Conversion to OrderedDict is deprecated for unordered associative containers (in this case, $(typeof(d))). Use an ordered or sorted associative type, such as SortedDict and OrderedDict.", :convert)
end
h = OrderedDict{K,V}()
for (k,v) in d
ck = convert(K,k)
if !haskey(h,ck)
h[ck] = convert(V,v)
else
error("key collision during dictionary conversion")
end
end
return h
end

isslotempty(slot_value::Integer) = slot_value == 0
isslotfilled(slot_value::Integer) = slot_value > 0
isslotmissing(slot_value::Integer) = slot_value < 0
Expand Down

0 comments on commit 68349aa

Please sign in to comment.