@@ -83,9 +83,9 @@ def _jupyterlab_variableinspector_getcontentof(x):
83
83
# pandas and numpy
84
84
if pd and isinstance(x, pd.DataFrame):
85
85
colnames = ', '.join(x.columns.map(str))
86
- content = "Column names: %s" % colnames
86
+ content = "Column names: %s" % colnames
87
87
elif pd and isinstance(x, pd.Series):
88
- content = "Series [%d rows]" % x.shape
88
+ content = "Series [%d rows]" % x.shape
89
89
elif np and isinstance(x, np.ndarray):
90
90
content = x.__repr__()
91
91
else:
@@ -150,15 +150,13 @@ def _jupyterlab_variableinspector_getmatrixcontent(x, max_rows=10000):
150
150
if threshold is not None:
151
151
x = x.head(threshold)
152
152
x.columns = x.columns.map(str)
153
- response = {"schema": pd.io.json.build_table_schema(x), "data": x.to_dict(orient="records")}
154
- return json.dumps(response, default=_jupyterlab_variableinspector_default)
153
+ return x.to_json(orient="table", default_handler=_jupyterlab_variableinspector_default)
155
154
elif np and pd and type(x).__name__ in ["ndarray"]:
156
155
df = pd.DataFrame(x)
157
156
if threshold is not None:
158
157
df = df.head(threshold)
159
158
df.columns = df.columns.map(str)
160
- response = {"schema": pd.io.json.build_table_schema(df), "data": df.to_dict(orient="records")}
161
- return json.dumps(response,default=_jupyterlab_variableinspector_default)
159
+ return df.to_json(orient="table", default_handler=_jupyterlab_variableinspector_default)
162
160
elif tf and (isinstance(x, tf.Variable) or isinstance(x, tf.Tensor)):
163
161
df = K.get_value(x)
164
162
return _jupyterlab_variableinspector_getmatrixcontent(df)
0 commit comments