ENH: Added to_json_schema by TomAugspurger · Pull Request #14904 · pandas-dev/pandas (original) (raw)
Lays the groundwork for (but doesn't close) #14386
This handles the schema part of the request there. We'll still need to
do the work to publish the data to the frontend, but that can be done
as a followup.
In [4]: df = pd.DataFrame( ...: {'A': [1, 2, 3], ...: 'B': ['a', 'b', 'c'], ...: 'C': pd.date_range('2016-01-01', freq='d', periods=3), ...: }, index=pd.Index(range(3), name='idx')) ...: df ...: Out[4]: A B C idx 0 1 a 2016-01-01 1 2 b 2016-01-02 2 3 c 2016-01-03
In [5]:
In [5]: pd.to_json_schema(df) Out[5]: {'fields': [{'name': 'idx', 'type': 'integer'}, {'name': 'A', 'type': 'integer'}, {'name': 'B', 'type': 'string'}, {'name': 'C', 'type': 'date'}], 'primary_key': 'idx'}
I think this is useful enough on its own to be part of the public API, so I've documented as such.
I've included a placeholder publish_tableschema
that will not be included in the final commit.
It's just to make @rgbkrk's life easier for prototyping the nteract frontend. I think the proper solution for publishing the schema + data will have to wait on ipython/ipython#10090