-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
pd.read_json and orient="index" sorts results #28557
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
Comments
Hi ! This is the result you expected, right? ...
>>> pd.read_json(df.to_json(orient="index"), orient="index")
0
3 0
2 1
1 2 |
Yes that's correct, at least for Py36 and above. The lines where this is happening is here: pandas/pandas/io/json/_json.py Line 1114 in ffe6cfd
So for now look in pandas.compat for the PY35 directive and only sort for that. Py36 and above won't need extra handling. We'll eventually be ripping out Py35 by the time this gets released but good to do it that way so the subsequent clean up is easily recognizable. |
I have completed the code modification to resolve the issue you mentioned. However, an error occurs because the existing test file is checking the sorting at Py36 and above. pandas/pandas/tests/io/json/test_pandas.py Lines 171 to 173 in 4fb853f
Therefore, can I modify the test file to solve the errors, and then move on to PR? |
Yep the text will need to change to only sort on Py35 |
Note that the order of input is not maintained with orient="index"
This is not necessarily a problem as by definition JSON objects are unordered, but preserving the order here would be a logical follow up to #27309
The text was updated successfully, but these errors were encountered: