Skip to content

ENH: Let Series/DataFrame initialisation from dicts use insertion order when python>=3.6 #19018

Closed
@topper-123

Description

@topper-123

Since Python 3.6 dicts have for practical purposes been ordered by insertion order in CPython, and from Cpython 3.7 dicts will be formally ordered by insertion order in the language specs.

Pandas currently orders series/dataframe comstructed from dict alphabetically. I propose to make the sort order dependent on python version, so Python <3.6 will keep the current behavior, while Python >= 3.6 will use insertion order.

I have played a bit with this and the code changes seem to be minimal (change a line in _init_dict in each of series.py/frame.py). After making the changes only 36 tests are failing, which is good. Updating the tests will mainly consists of making the columns order fixed in places (i.e. add a columns=[...] for dataframes and index=[...] for series), so I predict this would not be a huge PR.

I could take this on, if there's agreement.

EDIT: Ok, sparse/frame.py will also have its _init_dict changed, but still I think this will be a small code change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions