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

to_json/read_json can't handle interval index #35420

Open
konstantinmiller opened this issue Jul 27, 2020 · 2 comments
Open

to_json/read_json can't handle interval index #35420

konstantinmiller opened this issue Jul 27, 2020 · 2 comments
Labels
Bug Interval Interval data type IO JSON read_json, to_json, json_normalize

Comments

@konstantinmiller
Copy link

Serializing a data frame with an interval index to JSON and then deserializing it fails to recover the index. Here is an example:

df = pd.DataFrame(index=pd.IntervalIndex(closed='left', dtype='interval[int64]', 
                                         data=[pd.Interval(0, 2, closed='left')]), 
                  data={'a': [42'})
serialized = df.to_json(orient='table')
deserialized = pd.read_json(serialized, orient='table')

Looking at serialized reveals that the interval index is serialized as any type looking like that:

{"closed":"left","closed_right":false,"left":0,"mid":0.5,"open_right":true,"right":1}

and looking at deserialized.index[0] reveals that the interval type wasn't recovered but rather the de-serialized value is still a dict:

{'closed': 'left',
 'closed_right': False,
 'left': 0,
 'mid': 1.0,
 'open_right': True,
 'right': 2}
@konstantinmiller konstantinmiller added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 27, 2020
@konstantinmiller konstantinmiller changed the title to_json()/read_json() can't handle interval index to_json/read_json can't handle interval index Jul 27, 2020
@simonjayhawkins
Copy link
Member

@konstantinmiller Thanks for the report. I can confirm that the issue exists on master.

@simonjayhawkins simonjayhawkins added Interval Interval data type IO JSON read_json, to_json, json_normalize and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 27, 2020
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Jul 27, 2020
@simonjayhawkins
Copy link
Member

xref #32037

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Interval Interval data type IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

No branches or pull requests

3 participants