Skip to content

json with multiindex and orient=split, fail to read what has been written #11674

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
mchevann opened this issue Nov 22, 2015 · 1 comment
Closed
Labels
IO JSON read_json, to_json, json_normalize MultiIndex

Comments

@mchevann
Copy link

Summary

Attempting to read a JSON file that has been written with orient="split" and a multi index is failing.
Pandas '0.17.0' on Python 3.5.0.

Observations

It works with orient=columns
It works when there is no multiindex
The output seems ok, the issue is probably on the decoding

Test case

import pandas as pd
df=pd.DataFrame([[1,2,3,4],[3,4,5,6],[7,8,9,10]],columns=["a","b","c","d"]).groupby(["a","b"]).sum()
df.to_json("t.json",orient="split")
pd.read_json("t.json",orient="split")

Error message

Traceback (most recent call last):

File "", line 1, in
pd.read_json("t.json",orient="split")

File "C:\Users\mchevann\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\json.py", line 210, in read_json
date_unit).parse()

File "C:\Users\mchevann\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\json.py", line 278, in parse
self._parse_no_numpy()

File "C:\Users\mchevann\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\json.py", line 502, in _parse_no_numpy
self.obj = DataFrame(dtype=None, **decoded)

File "C:\Users\mchevann\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\frame.py", line 277, in init
dtype=dtype)

File "C:\Users\mchevann\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\frame.py", line 5102, in _arrays_to_mgr
return create_block_manager_from_arrays(arrays, arr_names, axes)

File "C:\Users\mchevann\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\internals.py", line 3805, in create_block_manager_from_arrays
construction_error(len(arrays), arrays[0].shape, axes, e)

File "C:\Users\mchevann\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\internals.py", line 3771, in construction_error
passed,implied))

ValueError: Shape of passed values is (2, 3), indices imply (2, 2)

@jreback
Copy link
Contributor

jreback commented Nov 22, 2015

this is a dupe of #4889

@jreback jreback closed this as completed Nov 22, 2015
@jreback jreback added IO JSON read_json, to_json, json_normalize MultiIndex labels Nov 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize MultiIndex
Projects
None yet
Development

No branches or pull requests

2 participants