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

filter(f, keys(::OrderedDict)) gives an unordered Set #147

Open
MasonProtter opened this issue Feb 21, 2025 · 0 comments
Open

filter(f, keys(::OrderedDict)) gives an unordered Set #147

MasonProtter opened this issue Feb 21, 2025 · 0 comments

Comments

@MasonProtter
Copy link

I ran into some surprising bugs recently due to this unexpected behaviour:

julia> d = OrderedDict(1 => :a, 2 => :b, 3 => :c);

julia> filter(iseven, keys(d))
Set{Int64} with 1 element:
  2

julia> filter(isodd, keys(d))
Set{Int64} with 2 elements:
  3
  1

It seems that the problem is that keys(::OrderedDict)::Base.KeySet. KeySet preserves the order, but filter on the KeySet produces a Base.Set.

I think this package should have its own KeySet like type with its own dispatches so it acts correctly in the face of things like filter.

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