Skip to content

Published display outputs are not included in %notebook magic #1433

@krassowski

Description

@krassowski

IPython 9.1 enhanced the %notebook magic so that the outputs are now stored too (ipython/ipython#14780). This allows users to spawn an ipython interpreter, a jupyter kernel, or jupyter console and later save their session to an .ipynb file for reference.

However, when using ipykernel (this is jupyter kernel, jupyter console and notebook interfaces) outputs generated via display publisher such as matplotlib plots are lost.

This is because the DisplayPublisher.publish() gets overridden by ipykernel in ZMQDisplayPublisher.publish() without calling the parent method, thus the code which was added in DisplayPublisher.publish():

outputs = self.shell.history_manager.outputs
outputs[self.shell.execution_count].append(
    HistoryOutput(output_type="display_data", bundle=data)
)

does not run. The ZMQDisplayPublisher.publish implementation is in:

def publish( # type:ignore[override]
self,
data,
metadata=None,
*,
transient=None,
update=False,
**kwargs,
):
"""Publish a display-data message

I think it would be useful to add this block, but I am not sure if this should be behind a feature flag (to avoid memory duplication for outputs).

Any opinions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions