-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Implement update_display #10048
Implement update_display #10048
Conversation
and display(display_id='...') for updating display_data outputs in-place.
""" | ||
from IPython.core.interactiveshell import InteractiveShell | ||
InteractiveShell.instance().display_pub.publish( | ||
data=data, | ||
metadata=metadata, | ||
transient=transient, | ||
**kwargs |
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.
Leaving room for later I see. 😄
metadata = kwargs.pop('metadata', None) | ||
transient = kwargs.setdefault('transient', {}) | ||
if 'display_id' in kwargs: | ||
transient['display_id'] = kwargs.pop('display_id') |
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.
👍
def update_display(*objs, **kwargs): | ||
"""Update an existing display""" | ||
kwargs['update'] = True | ||
return display(*objs, **kwargs) |
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 like that I can use display
with update
= True and not have to use update_display
directly as a function. 😄 /cc @ivanov
avoids unnecessary errors with older ipykernel passing display_id or transient will trigger TypeError: unsupported arg on ipykernel that doesn't support transient data
- display(display_id=True) generates new display_id - display(display_id=anything) returns DisplayHandle
Here's an example demonstrating this with current master of ipykernel, notebook now that those PRs have been merged. This is my interpretation of proposals from @fperez and @jasongrout about creating a handle and auto-generating a display_id with a boolean flag (in this case, I used
So the quickest way to create and update a display without needing to generate an id yourself: handle = display(x, display_id=True)
handle.update(y)
handle.update(z) Possible functionality that is currently excluded:
|
@@ -78,7 +79,7 @@ def _display_mimetype(mimetype, objs, raw=False, metadata=None): | |||
# Main functions | |||
#----------------------------------------------------------------------------- | |||
|
|||
def publish_display_data(data, metadata=None, source=None, transient=None, **kwargs): | |||
def publish_display_data(data, metadata=None, source=None, *, transient=None, **kwargs): |
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.
@minrk What does the *
represent? Or typo?
|
||
def update_display(obj, *, display_id, **kwargs): |
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.
Would be good to explain *
in docstring here and above. Thanks!
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.
It is in the docstring, in that *
is Python's syntax to denote the end of positional args and display_id
is labeled as keyword-only in the docstring. What would you recommend for comments regarding adopting new Python syntax?
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.
Wow, didn't realize that was available as a feature in Python. 😎
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 added some comments on the methods to clarify these. Thanks!
For @Carreau, @takluyver: I made use of the fact that we are Python 3-only now by making some new args explicitly keyword-only but still in the signature. Hooray for progress! We can refine/revise the APIs in subsequent PRs, but this one is complete enough for people to play with and build opinions about, I think. Thanks, @rgbkrk! |
@minrk Thanks for the clarification re: '*' and arguments. I hadn't seen it used in the wild yet ;-) |
Sweet ! @willingc , you will also see
It means "end of positional only arguments". Above it means that |
Oh does this mean no update display in Python 2 for now? I misconstrued earlier sentiment that we'd keep doing a python 2 kernel for a bit and enforcing python 3 for services (notebook, hub). |
We're planning to keep supporting IPython 5 for Python 2 users for some time, but make IPython 6 require Python 3. As this is a new feature in IPython, Min has targeted it for IPython 6. We could maybe make a distinction between user-facing features and infrastructure features, and allow backporting some of the latter. I'd be -0.25 on doing that. Separately, at some point the applications will require Python 3. Hub already does. For those, we don't plan to make an LTS version with Python 2 support as we have for IPython. |
I'm okay targeting this for 5.x as well, if people have that preference. I just wanted to note that my experience was slightly improved by the fact that IPython 6 has dropped py2 support. The differences are small, so it wouldn't be a big deal to backport. It is only |
Ok, great. I'll use |
I would be ok backporting. My Backporting bot that you can just |
TIL @mention is a reserved name on github so you don't need to take extra-care when writing it. |
@Carreau would you be willing to backport this one? It's the feature I want to use and support across PySpark installations for updating job statuses. |
I think that is reasonable enough to make API used by many package like TQDM consistant between stable version. Let's see if it applies cleanly to 5.x @meeseeksdev backport |
Oops, something went wrong applying the patch... Please have a look at my logs. |
Ok, may need manual backport. |
Implement update_display (94d6f5b)
Backport PR #10048 on branch 5.x
sets a display id.
updates the display in-place.
This is implemented through adding the
transient
dict to display-data, wheredisplay_id
resides.Still todo: