Skip to content

Commit 8b3ae3c

Browse files
committed
Only collect one time during display() in jupyter notebooks
1 parent 39b5971 commit 8b3ae3c

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
@@ -149,6 +149,16 @@ def __repr__(self) -> str:
149149
Returns:
150150
String representation of the DataFrame.
151151
"""
152+
# Check if we're in IPython/Jupyter. If so, we will only use
153+
# the _repr_html_ output to avoid calling collect() twice.
154+
try:
155+
from IPython import get_ipython
156+
157+
if get_ipython() is not None:
158+
return "" # Return empty string to effectively disable
159+
except ImportError:
160+
pass
161+
152162
return self.df.__repr__()
153163

154164
def _repr_html_(self) -> str:

0 commit comments

Comments
 (0)