Skip to content

Commit 87d0a21

Browse files
authored
Fixed index retrival for dts w/ multiindex (#46)
1 parent cade657 commit 87d0a21

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/inspectorscripts.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ def _jupyterlab_variableinspector_getcontentof(x):
8383
# pandas and numpy
8484
if pd and isinstance(x, pd.DataFrame):
8585
colnames = ', '.join(x.columns.map(str))
86-
content = "Column names: %s" % colnames
86+
content = "Column names: %s" % colnames
8787
elif pd and isinstance(x, pd.Series):
88-
content = "Series [%d rows]" % x.shape
88+
content = "Series [%d rows]" % x.shape
8989
elif np and isinstance(x, np.ndarray):
9090
content = x.__repr__()
9191
else:
@@ -150,15 +150,13 @@ def _jupyterlab_variableinspector_getmatrixcontent(x, max_rows=10000):
150150
if threshold is not None:
151151
x = x.head(threshold)
152152
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)
155154
elif np and pd and type(x).__name__ in ["ndarray"]:
156155
df = pd.DataFrame(x)
157156
if threshold is not None:
158157
df = df.head(threshold)
159158
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)
162160
elif tf and (isinstance(x, tf.Variable) or isinstance(x, tf.Tensor)):
163161
df = K.get_value(x)
164162
return _jupyterlab_variableinspector_getmatrixcontent(df)

0 commit comments

Comments
 (0)