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

sort doesn't receive the pairs if operating on pairs of Dicts #40665

Closed
mschauer opened this issue Apr 29, 2021 · 1 comment
Closed

sort doesn't receive the pairs if operating on pairs of Dicts #40665

mschauer opened this issue Apr 29, 2021 · 1 comment

Comments

@mschauer
Copy link
Contributor

mschauer commented Apr 29, 2021

sort doesn't receive the pairs if operating on pairs of Dicts

julia> sort(pairs(cnt), by=x->x.second)
ERROR: type Int64 has no field second
Stacktrace:
  [1] getproperty(x::Int64, f::Symbol)
    @ Base ./Base.jl:33
  [2] (::var"#45#46")(x::Int64)
    @ Main ./REPL[74]:1
  [3] lt(o::Base.Order.By{var"#45#46", Base.Order.ForwardOrdering}, a::Int64, b::Int64)
    @ Base.Order ./ordering.jl:111
  [4] lt
    @ ./ordering.jl:117 [inlined]
  [5] selectpivot!
    @ ./sort.jl:557 [inlined]
  [6] partition!(v::Vector{Int64}, lo::Int64, hi::Int64, o::Base.Order.Perm{Base.Order.By{var"#45#46", Base.Order.ForwardOrdering}, Vector{Int64}})
    @ Base.Sort ./sort.jl:579
  [7] sort!
    @ ./sort.jl:600 [inlined]
  [8] sort!(v::Vector{Int64}, alg::Base.Sort.QuickSortAlg, order::Base.Order.Perm{Base.Order.By{var"#45#46", Base.Order.ForwardOrdering}, Vector{Int64}})
    @ Base.Sort ./sort.jl:687
  [9] sortperm(v::Vector{Int64}; alg::Base.Sort.QuickSortAlg, lt::Function, by::Function, rev::Nothing, order::Base.Order.ForwardOrdering)
    @ Base.Sort ./sort.jl:952
 [10] sort!(d::OrderedCollections.OrderedDict{Int64, Int64}; byvalue::Bool, args::Base.Iterators.Pairs{Symbol, var"#45#46", Tuple{Symbol}, NamedTuple{(:by,), Tuple{var"#45#46"}}})
    @ OrderedCollections ~/.julia/packages/OrderedCollections/cP9uu/src/dict_sorting.jl:12
 [11] sort(d::Dict{Int64, Int64}; args::Base.Iterators.Pairs{Symbol, var"#45#46", Tuple{Symbol}, NamedTuple{(:by,), Tuple{var"#45#46"}}})
    @ OrderedCollections ./deprecated.jl:72
 [12] top-level scope
    @ REPL[74]:1

where Julia Version 1.6.0 and

julia> eltype(pairs(cnt))
Pair{Int64, Int64}

julia> cnt
Dict{Int64, Int64} with 80200 entries:
  76914 => 41
  
julia> pairs(cnt) # Dict iterate themselves
Dict{Int64, Int64} 
  
@mschauer
Copy link
Contributor Author

Figured out that it is not Base but caused by type piracy in JuliaCollections/OrderedCollections.jl#25

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

No branches or pull requests

1 participant