Skip to content

Commit 1c80dcd

Browse files
committed
Only collect one time during display() in jupyter notebooks
1 parent 03921d9 commit 1c80dcd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

python/datafusion/dataframe.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@ def __repr__(self) -> str:
321321
Returns:
322322
String representation of the DataFrame.
323323
"""
324+
# Check if we're in IPython/Jupyter. If so, we will only use
325+
# the _repr_html_ output to avoid calling collect() twice.
326+
try:
327+
from IPython import get_ipython
328+
329+
if get_ipython() is not None:
330+
return "" # Return empty string to effectively disable
331+
except ImportError:
332+
pass
333+
324334
return self.df.__repr__()
325335

326336
def _repr_html_(self) -> str:

0 commit comments

Comments
 (0)