File tree Expand file tree Collapse file tree 2 files changed +11
-90
lines changed Expand file tree Collapse file tree 2 files changed +11
-90
lines changed Original file line number Diff line number Diff line change 11from IPython .display import display , DisplayObject
22import json
33import pandas as pd
4- from .utils import prepare_data
54
65
76# Running `npm run build` will create static resources in the static
@@ -22,6 +21,16 @@ def _jupyter_nbextension_paths():
2221 'require' : 'jupyterlab_table/extension'
2322 }]
2423
24+ def prepare_data (data = None , schema = None ):
25+ """Prepare JSONTable data from Pandas DataFrame."""
26+
27+ if isinstance (data , pd .DataFrame ):
28+ data = data .to_json (orient = 'table' )
29+ return json .loads (data )
30+ return {
31+ 'data' : data ,
32+ 'schema' : schema
33+ }
2534
2635# A display class that can be used within a notebook. E.g.:
2736# from jupyterlab_table import JSONTable
@@ -88,9 +97,7 @@ def schema(self, schema):
8897
8998 def _ipython_display_ (self ):
9099 bundle = {
91- 'application/vnd.dataresource+json' : {
92- 'resources' : [prepare_data (self .data , self .schema )]
93- },
100+ 'application/vnd.dataresource+json' : prepare_data (self .data , self .schema ),
94101 'text/plain' : '<jupyterlab_table.JSONTable object>'
95102 }
96103 metadata = {
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments