Skip to content

Commit 5c907bf

Browse files
committed
Speedup big dictionaries
1 parent cdfe7bd commit 5c907bf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/inspectorscripts.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export abstract class Languages {
1616
static py_script = `import json
1717
import sys
1818
from importlib import __import__
19+
from itertools import islice
20+
import collections
1921
from IPython import get_ipython
2022
from IPython.core.magics.namespace import NamespaceMagics
2123
@@ -108,6 +110,17 @@ def _jupyterlab_variableinspector_getcontentof(x):
108110
content = str(x)
109111
else:
110112
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 += ", ...}"
111124
elif __pd and isinstance(x, __pd.DataFrame):
112125
colnames = ', '.join(x.columns.map(str))
113126
content = "Columns: %s" % colnames
@@ -159,7 +172,7 @@ def _jupyterlab_variableinspector_dict_list():
159172
def keep_cond(v):
160173
try:
161174
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))):
163176
return True
164177
if __tf and isinstance(obj, __tf.Variable):
165178
return True

0 commit comments

Comments
 (0)