Skip to content

Roundtrip orient for JSON #9146

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
Komnomnomnom opened this issue Dec 24, 2014 · 3 comments · Fixed by #19039
Closed

Roundtrip orient for JSON #9146

Komnomnomnom opened this issue Dec 24, 2014 · 3 comments · Fixed by #19039
Labels
API Design IO JSON read_json, to_json, json_normalize
Milestone

Comments

@Komnomnomnom
Copy link
Contributor

Add a round-trippable json orient (maybe "roundtrip") to provide enough metadata to reconstruct a frame or series with 100% fidelity. As discussed in #9130

@Komnomnomnom
Copy link
Contributor Author

This could also support multi-level indexes and panels etc.

@cpcloud
Copy link
Member

cpcloud commented Dec 24, 2014

@jreback and i are currently using a schema that looks somewhat like this:

schema = {
    'pandas': {
        'type': 'DataFrame',
        'version': pd.__version__,
        'orient': 'records',
        'date_unit': 'ms',
        'values': df,
        'dtypes': {
            'str': [dtype.str for dtype in dtypes],
            'characters': [dtype.char for dtype in dtypes],
            'kind': [dtype.kind for dtype in dtypes]
        },
        'axes': {
            'columns': {
                'values': df.columns.values,
                'dtype': df.columns.dtype.str,
                'names': df.columns.names
            },
            'index': {
                'values': df.index.values,
                'dtype': df.index.dtype.str,
                'names': df.index.names
            }
        }
    }
}

@jreback jreback added API Design IO JSON read_json, to_json, json_normalize labels Dec 24, 2014
@jreback jreback added this to the 0.16.0 milestone Dec 24, 2014
@jreback
Copy link
Contributor

jreback commented Dec 24, 2014

@Komnomnomnom

the idea is the encompas enough meta data to really make a DataFrame round tripable w/o passing anything, IOW, making it a fully-capable format. Of course its a 'user-made' one, but that is true with lots of formats.

I suspect lots of people have already implemented this (painfully) by creating their own formats. This is basically trying to set a standard, in that, pandas objects become JSON serializable in a well-defined format.

This can be done simply by using pandas.io.json.dumps with this format on the writing. @cpcloud mentioned that it might be necessary to support some sniffing the reader to de-serialize this format (e.g. look for the pandas tag then use the meta-data to set the next part of the serialization options).

The idea of the format is that it is pretty straightforward to extend to Series/Panel/Multi-Index.

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

Successfully merging a pull request may close this issue.

3 participants