Skip to content

Add OrderedDict to Base (for Julia 1.6?) #37761

Closed
@PallHaraldsson

Description

@PallHaraldsson

I would like to propose OrderedDict added (I guess unexported, at least for now), to Julia 1.6. When It or later version will be LTS, and Julia 1 dropped as LTS, I feel it important it is readily available in Base, to be available in all used Julia versions from the (faster) system image.

Why? You can use DataStructures.jl, but it's a hassle to add it to each library that needs this one important container (I just fixed a bug in Pandas, that would have worked by just renaming Dict to OrderedDict had it been available, or Base.OrderedDict in this proposal), and will slow down (on my recent master):

julia> @time using DataStructures: OrderedDict
  0.558825 seconds (461.80 k allocations: 28.509 MiB, 3.54% gc time)

This seems like a small PR, that I could even do. That code is available and fully baked, and think it's still Jeff's code, code I trust.

I'm NOT proposing changing the default of DIct to OrderedDict, at least for now, as I think it's still slower, and we can't really go back with that API decision. I note however that's what Python did:

"Ordered dictionaries are just like regular dictionaries but have some extra capabilities relating to ordering operations. They have become less important now that the built-in dict class gained the ability to remember insertion order (this new behavior became guaranteed in Python 3.7).
[..]
Until Python 3.8, dict lacked a reversed() method."

So, at a minimum I propose just A.:

A.
Add OrderedDict, I think it needs to be NOT exported to avoid conflict in case DataStructures.jl will also be used.

B.
I think we could make a "standard library" named Ordered, so that:

using Ordered

will change the meaning of Dict to OrderedDict.

C.
Maybe at some point in the future we can do B. by default, and add UnorderedDict.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions