-
Notifications
You must be signed in to change notification settings - Fork 39
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
Equality of OrderedDict #82
Comments
This is because it is falling back to the generic julia> od = OrderedDict(1=>2)
OrderedDict{Int64, Int64} with 1 entry:
1 => 2
julia> @which ==(od, od)
==(l::AbstractDict, r::AbstractDict) in Base at abstractdict.jl:468 Whether or not this is sensible is not clear to me. For what it is worth our behavour disagrees with python. >>> from collections import OrderedDict
>>> d = OrderedDict.fromkeys('abcde')
>>> d2 = OrderedDict.fromkeys('edcba')
>>> d==d2
False
>>> d==d
True Python treats ordered dicts as equal only if they have the same contents in the same order) |
I definitely expected that |
For any type |
@jariji that is a very vague characterization, it is not clear to me what that really would mean. If I understand you correctly (and I may not) then Julia is violating this principle already in many ways. E.g.:
Arguably OK perhaps you'll argue this doesn't count because one is an error. So how about this:
|
Don't get me wrong, this is not meant to argue that the current behavior is right / correct / preferable / whatever, just that I don't buy this particular argument. Another aspect to consider is that changing the behavior of Unlike some other breaking changes we may want to apply, like fixing some type piracy issues (see issue #25 ) this one is more tricky as it has the potential to introduce one of the worst kinds of bugs: code that previously worked correctly in downstream packages could be suddenly start producing wrong results. That is really undesirable. Thus, personally I think the ship has sailed on this one. If this was day 1, I'd be fine with taking the order into account, but there are now > 350 direct dependencies on this package in the ecosystem, and a couple thousand indirect one. Thus as outlined I believe changing this risks breaking too much code in a really bad way. The gain seems minimal. So I would say "By now, this is indeed as intended", and we should document it explicitly as such. To still help users, perhaps we could introduce a "compare while taking order into account" method. Say Also perhaps it would help to add a new mutable struct GenOrderedDict{K,V,strict} <: AbstractDict{K,V}
slots::Vector{Int32}
keys::Vector{K}
vals::Vector{V}
ndel::Int
maxprobe::Int
dirty::Bool
end
const OrderedDict{K,V} = GenOrderedDict{K,V,false}
const StrictOrderedDict{K,V} = GenOrderedDict{K,V,true} Of course then one still would have to duplicate a bunch of constructors and adjust other places to use Any code which currently only expects an |
@fingolfin I say "For any type |
but there is also the matter of transitivity: x == y and y == z should perhaps imply x == z (granted I am sure Julia also violates that already). In any case it does not change the fact that surely there is code out there relying on the current behavior, so changing it would be a (painful) breaking change |
I am a little confused by the following, is it intentional that
==
does not take into account the order of keys forOrderedDict
?this is mainly motivated by testing purposes, as I think in tests one wants to check that also the keys order is correct. Well, arguably one can always do
so maybe it's not a biggie.
The text was updated successfully, but these errors were encountered: