rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Extra Output Cell Created in Jupyter Notebook when using display

Open eehusky opened this issue 1 year ago • 7 comments

  • [x ] I've checked docs and closed issues for possible solutions.
  • [x ] I can't find my issue in the FAQ.

Describe the bug

%reload_ext rich
a = {
    0:0
};
display(a)

Here you can see the extra (but empty) output cell between the input and the displayed value.

image

I actually managed to track it down to this bit here.

https://github.com/Textualize/rich/blob/e9f75c9912ed25b9777bc0257853370951220b17/rich/console.py#L2007C22-L2007C22

                if self.is_jupyter:  # pragma: no cover
                    from .jupyter import display
                    display(self._buffer, self._render_buffer(self._buffer[:]))
                    del self._buffer[:]

The call to display, actually i think its the subsequent call to ipython_display is whats causing the extra cell?

This example is taken from vscode but it also appears in notebooks/jupyterlab.

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:

python -m rich.diagnose
pip freeze | grep rich

If you're using Rich in a Jupyter Notebook, run the following snippet in a cell and paste the output in your bug report.

from rich.diagnose import report
report()
╭──────────────────────── <class 'rich.console.Console'> ────────────────────────╮
│ A high level console interface.                                                │
│                                                                                │
│ ╭────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=115 ColorSystem.TRUECOLOR>                                  │ │
│ ╰────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                │
│     color_system = 'truecolor'                                                 │
│         encoding = 'utf-8'                                                     │
│             file = <ipykernel.iostream.OutStream object at 0x000001B3F7C525C0> │
│           height = 100                                                         │
│    is_alt_screen = False                                                       │
│ is_dumb_terminal = False                                                       │
│   is_interactive = False                                                       │
│       is_jupyter = True                                                        │
│      is_terminal = False                                                       │
│   legacy_windows = False                                                       │
│         no_color = False                                                       │
│          options = ConsoleOptions(                                             │
│                        size=ConsoleDimensions(width=115, height=100),          │
│                        legacy_windows=False,                                   │
│                        min_width=1,                                            │
│                        max_width=115,                                          │
│                        is_terminal=False,                                      │
│                        encoding='utf-8',                                       │
│                        max_height=100,                                         │
│                        justify=None,                                           │
│                        overflow=None,                                          │
│                        no_wrap=False,                                          │
│                        highlight=None,                                         │
│                        markup=None,                                            │
│                        height=None                                             │
│                    )                                                           │
│            quiet = False                                                       │
│           record = False                                                       │
│         safe_box = True                                                        │
│             size = ConsoleDimensions(width=115, height=100)                    │
│        soft_wrap = False                                                       │
│           stderr = False                                                       │
│            style = None                                                        │
│         tab_size = 8                                                           │
│            width = 115                                                         │
╰────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available.                         │
│                                                     │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│                                                     │
│ truecolor = True                                    │
│        vt = True                                    │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-color',         │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': '1',               │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'WezTerm',     │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': '4100',      │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Windows"

eehusky avatar Oct 25 '23 14:10 eehusky

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Oct 25 '23 14:10 github-actions[bot]

I commented out that entire block and everything still renders correctly and without the extra output cell but I dont know enough to say its not there for some other very good reason.

                if self.is_jupyter:  # pragma: no cover
                    pass
                    #from .jupyter import display
                    #display(self._buffer, self._render_buffer(self._buffer[:]))
                    #del self._buffer[:]

image

eehusky avatar Oct 25 '23 15:10 eehusky

heh, apparently that bit i commented out, while not impacting the display functionality, does prevent the traceback from being displayed when an exception occurs.

eehusky avatar Oct 25 '23 18:10 eehusky

same issue here, maybe it is problem with jupyter in VSCode.

puppyapple avatar Nov 09 '23 01:11 puppyapple

same issue here, maybe it is problem with jupyter in VSCode.

That was actually my first thought as well but I was able to reproduce it in the notebook and jupyterlab web interface as well as the jupyterlab standalone application.

eehusky avatar Nov 14 '23 18:11 eehusky

I've got the same problem but only in VSCode (v1.85.1). Output looks normal for Jupyterlab (v3.6.5 )

Bubblbu avatar Dec 16 '23 02:12 Bubblbu

Duplicate of #3329

NickCrews avatar Apr 12 '24 20:04 NickCrews