Skip to content

Commit 2260777

Browse files
committed
Only collect one time during display() in jupyter notebooks
1 parent bfd7a2d commit 2260777

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
@@ -318,6 +318,16 @@ def __repr__(self) -> str:
318318
Returns:
319319
String representation of the DataFrame.
320320
"""
321+
# Check if we're in IPython/Jupyter. If so, we will only use
322+
# the _repr_html_ output to avoid calling collect() twice.
323+
try:
324+
from IPython import get_ipython
325+
326+
if get_ipython() is not None:
327+
return "" # Return empty string to effectively disable
328+
except ImportError:
329+
pass
330+
321331
return self.df.__repr__()
322332

323333
def _repr_html_(self) -> str:

0 commit comments

Comments
 (0)