File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,9 @@ def _jupyterlab_variableinspector_getsizeof(x):
77
77
elif __torch and isinstance(x, __torch.Tensor):
78
78
return x.element_size() * x.nelement()
79
79
elif __pd and type(x).__name__ == 'DataFrame':
80
- return x.memory_usage().sum()
80
+ # DO NOT CALL df.memory_usage() as this can be very costly
81
+ # to the point of crashing the kernel
82
+ return "?"
81
83
else:
82
84
return sys.getsizeof(x)
83
85
@@ -136,8 +138,17 @@ def _jupyterlab_variableinspector_getcontentof(x):
136
138
content += f'"{key}": {x[key]}'
137
139
content += ", ...}"
138
140
elif __pd and isinstance(x, __pd.DataFrame):
139
- colnames = ', '.join(x.columns.map(str))
140
- content = "Columns: %s" % colnames
141
+ if len(x.columns) <= _jupyterlab_variableinspector_maxitems:
142
+ colnames = ', '.join(x.columns.map(str))
143
+ content = "Columns: %s" % colnames
144
+ else:
145
+ content = "Columns: "
146
+ for idx in range(_jupyterlab_variableinspector_maxitems):
147
+ if idx > 0:
148
+ content += ", "
149
+ content += str(x.columns[idx])
150
+ content += ", ..."
151
+ return content
141
152
elif __pd and isinstance(x, __pd.Series):
142
153
content = str(x.values).replace(" ", ", ")[1:-1]
143
154
content = content.replace("\\n", "")
You can’t perform that action at this time.
0 commit comments