@@ -16,6 +16,8 @@ export abstract class Languages {
16
16
static py_script = `import json
17
17
import sys
18
18
from importlib import __import__
19
+ from itertools import islice
20
+ import collections
19
21
from IPython import get_ipython
20
22
from IPython.core.magics.namespace import NamespaceMagics
21
23
@@ -108,6 +110,17 @@ def _jupyterlab_variableinspector_getcontentof(x):
108
110
content = str(x)
109
111
else:
110
112
content = f"[{x[0]}, {x[1]}, {x[2]}, ..., {x[-1]}]"
113
+ elif isinstance(x, collections.abc.Mapping):
114
+ if len(x.keys()) < 10:
115
+ content = str(x)
116
+ else:
117
+ first_ten_keys = list(islice(x.keys(), 10))
118
+ content = "{"
119
+ for idx, key in enumerate(first_ten_keys):
120
+ if idx > 0:
121
+ content += ", "
122
+ content += f'"{key}": {x[key]}'
123
+ content += ", ...}"
111
124
elif __pd and isinstance(x, __pd.DataFrame):
112
125
colnames = ', '.join(x.columns.map(str))
113
126
content = "Columns: %s" % colnames
@@ -159,7 +172,7 @@ def _jupyterlab_variableinspector_dict_list():
159
172
def keep_cond(v):
160
173
try:
161
174
obj = eval(v)
162
- if isinstance(obj, (bool, str, list, tuple, int, float, type(None))):
175
+ if isinstance(obj, (bool, str, list, tuple, collections.abc.Mapping, int, float, type(None))):
163
176
return True
164
177
if __tf and isinstance(obj, __tf.Variable):
165
178
return True
0 commit comments