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

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

Closed
topper-123 opened this issue Dec 31, 2017 · 1 comment · Fixed by #19884
Closed

Comments

@topper-123
Copy link
Contributor

topper-123 commented Dec 31, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants