File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -89,12 +89,7 @@ def schema(self, schema):
8989 def _ipython_display_ (self ):
9090 bundle = {
9191 'application/vnd.dataresource+json' : {
92- 'resources' : [
93- {
94- 'schema' : self .schema ,
95- 'data' : prepare_data (self .data )
96- }
97- ]
92+ 'resources' : [prepare_data (self .data , self .schema )]
9893 },
9994 'text/plain' : '<jupyterlab_table.JSONTable object>'
10095 }
Original file line number Diff line number Diff line change 22import codecs
33import collections
44import os .path
5+ import json
56import pandas as pd
67
78
@@ -72,10 +73,14 @@ def sanitize_dataframe(df):
7273 return df
7374
7475
75- def prepare_data (data = None ):
76- """Prepare Plotly data from Pandas DataFrame."""
76+ def prepare_data (data = None , schema = None ):
77+ """Prepare JSONTable data from Pandas DataFrame."""
7778
78- if isinstance (data , list ):
79- return data
80- data = sanitize_dataframe (data )
81- return data .to_dict (orient = 'records' )
79+ if isinstance (data , pd .DataFrame ):
80+ data = sanitize_dataframe (data )
81+ data = data .to_json (orient = 'table' )
82+ return json .loads (data )
83+ return {
84+ 'data' : data ,
85+ 'schema' : schema
86+ }
You can’t perform that action at this time.
0 commit comments