Skip to content

Commit 722d65d

Browse files
committed
Only show memory usage of relatively small dataframes
1 parent c99f867 commit 722d65d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/inspectorscripts.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ def _jupyterlab_variableinspector_getsizeof(x):
7777
elif __torch and isinstance(x, __torch.Tensor):
7878
return x.element_size() * x.nelement()
7979
elif __pd and type(x).__name__ == 'DataFrame':
80-
# DO NOT CALL df.memory_usage() as this can be very costly
81-
# to the point of crashing the kernel
82-
return "?"
80+
# DO NOT CALL df.memory_usage() for big dataframes as this can be very costly
81+
# to the point of making the kernel unresponsive or crashing it
82+
if len(x.columns) < 10_000:
83+
return x.memory_usage().sum()
84+
else:
85+
return "?"
8386
else:
8487
return sys.getsizeof(x)
8588

0 commit comments

Comments
 (0)