Skip to content

Commit b1dcd99

Browse files
Olivia-liufacebook-github-bot
authored andcommitted
Make print_data_tabular work for both terminal and notebook environment
Differential Revision: D49784817 fbshipit-source-id: 42f613324a26c1faea72e73b28df5619e6440ec4
1 parent 3f535e0 commit b1dcd99

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sdk/etdb/inspector.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,17 @@ def style_text_size(val, size=12):
429429
# Filter out some columns for better readability when printing
430430
filtered_df = combined_df.drop(columns=EXCLUDED_COLUMNS_WHEN_PRINTING)
431431
try:
432+
from IPython import get_ipython
432433
from IPython.display import display
433434

434-
styled_df = filtered_df.style.applymap(style_text_size)
435-
display(styled_df)
435+
if get_ipython() is not None:
436+
styled_df = filtered_df.style.applymap(style_text_size)
437+
display(styled_df)
438+
else:
439+
raise Exception(
440+
"Environment unable to support IPython. Fall back to print()."
441+
)
436442
except:
437-
# TODO: figure out how to trigger this path in python shell
438443
print(tabulate(filtered_df, headers="keys", tablefmt="fancy_grid"))
439444

440445
# TODO: write unit test

0 commit comments

Comments
 (0)