Skip to content

to_json/read_json can't handle interval index #35420

Open
@konstantinmiller

Description

@konstantinmiller

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO JSONread_json, to_json, json_normalizeIntervalInterval data type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions