Skip to content

Inner dictionaries are not displaying in insertion order #25911

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

Closed
boardtc opened this issue Mar 28, 2019 · 4 comments
Closed

Inner dictionaries are not displaying in insertion order #25911

boardtc opened this issue Mar 28, 2019 · 4 comments
Labels
Bug DataFrame DataFrame data structure

Comments

@boardtc
Copy link

boardtc commented Mar 28, 2019

Code Sample

newspapers = {'Jim':{'Mon':15,'Tue':17,'Wed':21,'Thu':16,'Fri':19},\
     'Tony':{'Mon':8,'Tue':15,'Wed':11,'Thu':16,'Fri':13}, \
     'Colin':{'Mon':13,'Tue':17,'Wed':19,'Thu':17,'Fri':20} \
    }
newspapers_df = pd.DataFrame(newspapers)

print(newspapers_df)

Problem description

I am using a recent download of Anaconda with Python 3.7.1 & pandas 0.23.4
The pandas doc says:

When the data is a dict, and an index is not passed, the Series index will be ordered by the dict’s insertion order

I instantiate a pandas DataFrame from a dict with no index passed, and print outputs:

Expected Output

     Jim  Tony  Colin
Mon   15     8     13
Tue   17    15     17
Wed   21    11     19
Thu   16    16     17
Fri   19    13     20

Output of `0.23.4``

      Jim  Tony  Colin
Fri   19    13     20
Mon   15     8     13
Thu   16    16     17
Tue   17    15     17
Wed   21    11     19
@mroeschke
Copy link
Member

Could you test this on the latest version of pandas (0.24.2) and master?

I suspect this check is too strict and should be checking for >PY36

if PY36 or isinstance(mapping, OrderedDict):

@alexander-ponomaroff
Copy link
Contributor

@mroeschke I tested and this also exists on master. I believe that PY36 check also checks for anything above Python 3.6 from what I remember.

I found what causes this issue and will be making a PR later tonight with a fix for this. One of the functions that gets called has a parameter to sort the Index, this is what is causing the order to be sorted here.

@WillAyd
Copy link
Member

WillAyd commented Apr 2, 2019

Discussed this in associated PR but this isn't something we want to make guarantees about. Closing as won't fix / no change

@WillAyd WillAyd closed this as completed Apr 2, 2019
@WillAyd WillAyd added this to the No action milestone Apr 2, 2019
@boardtc
Copy link
Author

boardtc commented May 28, 2019

Discussed this in associated PR but this isn't something we want to make guarantees about. Closing as won't fix / no change

Why is the community happy to keep a bug in the code?

The logic in the PR is incorrect. From a python-dev message by GvR: "Dict keeps insertion order"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DataFrame DataFrame data structure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants