Skip to content

Commit 05a5440

Browse files
committed
Use df.to_json vs. sanitize_dataframe
1 parent f121a9a commit 05a5440

File tree

2 files changed

+11
-90
lines changed

2 files changed

+11
-90
lines changed

jupyterlab_table/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from IPython.display import display, DisplayObject
22
import json
33
import 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 = {

jupyterlab_table/utils.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)