Skip to content
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

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

Open
eehusky opened this issue Oct 25, 2023 · 7 comments
Open

Comments

@eehusky
Copy link

eehusky commented Oct 25, 2023

  • [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"
@github-actions
Copy link

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

@eehusky
Copy link
Author

eehusky commented Oct 25, 2023

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
Copy link
Author

eehusky commented Oct 25, 2023

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

@puppyapple
Copy link

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

@eehusky
Copy link
Author

eehusky commented Nov 14, 2023

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.

@Bubblbu
Copy link

Bubblbu commented Dec 16, 2023

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

@NickCrews
Copy link

Duplicate of #3329

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants