-
Notifications
You must be signed in to change notification settings - Fork 116
feat: collect once during display() in jupyter notebooks #1167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: collect once during display() in jupyter notebooks #1167
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a reasonable workaround because there are many Jupyter-protocol frontends that do not support displaying HTML output. This means that repr would be broken for the IPython console, for example
Ref https://discourse.jupyter.org/t/find-out-if-my-code-runs-inside-a-notebook-or-jupyter-lab/6935/8 You might be able to look in the IPython config to see what's running, but this answer is 10+ years old and might've changed https://stackoverflow.com/a/24937408 |
Thanks for the feedback! I changed to check for the environment as you suggested and tested in jupyter, ipython console, and regular python console. |
As mentioned in a comment on SO, that fails in ![]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that looks a lot more stable, even though it's kinda annoying
… between jupyter console and notebook
…n we have any kind if ipython environment.
8d65e99
to
ae65240
Compare
Which issue does this PR close?
None
Rationale for this change
By design in a Jupyter notebook
display()
calls both__repr__
and_repr_html_
. This currently causescollect()
on DataFrames to occur twice, which can lead to double the execution time during evaluation. This PR causes collect to only happen once.What changes are included in this PR?
If we are in a jupyter notebook, we will cache the result of a
__repr__
or_repr_html_
call. When the other call happens, it will consume the cached calls. This means that fordisplay()
in a jupyter notebook the collected data will be freed.Are there any user-facing changes?
None.