Skip to content

[Bug]: Bug with toolbar instantiation in notebook #23699

Closed
@larsoner

Description

@larsoner

Bug summary

In MNE-Python we have an abstraction layer for widgets+toolbars. Until today's latest pip --pre install it was working fine. Now it fails with:

E   TraitError: The 'toolbar' trait of a Canvas instance expected a Toolbar or None, not the NavigationToolbar2WebAgg at '0x7fce12bf6f80'.

See https://dev.azure.com/mne-tools/mne-python/_build/results?buildId=21230&view=logs&jobId=2b5832ae-6860-5681-a4e1-fd132048f8b4&j=2b5832ae-6860-5681-a4e1-fd132048f8b4&t=5b9d2bdb-d99e-53c3-c7bb-7166fe849ae1

Code for reproduction

I'll work on boiling it down to a MWE tomorrow hopefully. Could also be a bug with traitlets. But the code that runs on the CIs is essentially this in a notebook I think:

plt.ioff()
fig, ax = plt.subplots()

Actual outcome

Full traceback
E   nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
E   ------------------
E   """Test the GUI widgets abstraction in notebook."""
E   from mne.viz import set_3d_backend
E   from mne.viz.backends.renderer import _get_backend
E   from mne.viz.backends.tests.test_abstract import _do_widget_tests
E   from IPython import get_ipython
E   
E   set_3d_backend('notebook')
E   backend = _get_backend()
E   
E   ipython = get_ipython()
E   ipython.magic('%matplotlib widget')
E   
E   _do_widget_tests(backend)
E   ------------------
E   
E   ---------------------------------------------------------------------------
E   TraitError                                Traceback (most recent call last)
E   Input In [1], in <cell line: 13>()
E        10 ipython = get_ipython()
E        11 ipython.magic('%matplotlib widget')
E   ---> 13 _do_widget_tests(backend)
E   
E   File ~/work/1/s/mne/viz/backends/tests/test_abstract.py:23, in _do_widget_tests(backend)
E        21 renderer.sphere([0, 0, 0], 'red', 1)
E        22 central_layout._add_widget(renderer.plotter)
E   ---> 23 canvas = backend._Canvas(5, 5, 96)
E        24 canvas.ax.plot(range(10), range(10), label='plot')
E        25 central_layout._add_widget(canvas)
E   

Expected outcome

No error

Additional information

EDIT: ipympl 0.9.2

Operating system

Ubuntu (GH actions), or macOS M1 (locally)

Matplotlib Version

3.6.0rc1

Matplotlib Backend

Notebook

Python version

3.10

Jupyter version

EDIT: 6.4.11

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions