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 in patching of rcParams #606

Open
astrofrog opened this issue Apr 16, 2024 · 2 comments · May be fixed by #992
Open

Bug in patching of rcParams #606

astrofrog opened this issue Apr 16, 2024 · 2 comments · May be fixed by #992

Comments

@astrofrog
Copy link
Contributor

I'm running into the following failure over in glue-jupyter:

/usr/lib/python3.11/contextlib.py:137: in __enter__
    return next(self.gen)
../../.tox/py311-test-visual/lib/python3.11/site-packages/pytest_mpl/plugin.py:318: in switch_backend
    prev_backend = matplotlib.get_backend().lower()
../../.tox/py311-test-visual/lib/python3.11/site-packages/matplotlib/__init__.py:1275: in get_backend
    return rcParams['backend']
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = RcParamsScoped({'_internal.classic_mode': True,
                'agg.path.chunksize': 0,
                'animation.bi...          'ytick.minor.visible': False,
                'ytick.minor.width': 0.5,
                'ytick.right': True})
key = 'backend'

    def __getitem__(self, key):
>       return self._get_context_dict().__getitem__(key)
E       KeyError: 'backend'

basically it seems the backend key is missing from the patched rcParams.

@maartenbreddels
Copy link
Contributor

Hi Tom,

I have trouble reproducing this. Do you have more details for me?

cheers,

Maarten

@astrofrog
Copy link
Contributor Author

astrofrog commented Jan 10, 2025

@maartenbreddels - here's a minimal reproducer:

python -m venv clean
source clean/bin/activate
pip install solara[pytest] "pytest-playwright<0.6" matplotlib pytest-mpl

then create a file test.py with:

import pytest

@pytest.mark.mpl_image_compare()
def test_basic(
    tmp_path,
    page_session,
    solara_test,
):
    pass

then:

pytest test.py --mpl

The error is:

self = RcParamsScoped({'_internal.classic_mode': 'True',
                'agg.path.chunksize': '0',
                'animatio...    'ytick.minor.visible': 'False',
                'ytick.minor.width': '0.5',
                'ytick.right': 'True'})
key = 'backend'

    def __getitem__(self, key):
>       return self._get_context_dict().__getitem__(key)
E       KeyError: 'backend'

clean/lib/python3.11/site-packages/solara/server/patch.py:195: KeyError

The issue happens when using pytest-mpl.

maartenbreddels added a commit that referenced this issue Jan 31, 2025
Our .clear on RcParams was working, while matplotlib was a no-op:
   matplotlib/matplotlib#25855

We now mirror this behaviour.

Fixes #606
maartenbreddels added a commit that referenced this issue Jan 31, 2025
Our .clear on RcParams was working, while matplotlib was a no-op:
   matplotlib/matplotlib#25855

We now mirror this behaviour.

Fixes #606
maartenbreddels added a commit that referenced this issue Jan 31, 2025
Our .clear on RcParams was working, while matplotlib was a no-op:
   matplotlib/matplotlib#25855

We now mirror this behaviour.

Fixes #606
iisakkirotko pushed a commit that referenced this issue Jan 31, 2025
Our .clear on RcParams was working, while matplotlib was a no-op:
   matplotlib/matplotlib#25855

We now mirror this behaviour.

Fixes #606
maartenbreddels added a commit that referenced this issue Jan 31, 2025
Our .clear on RcParams was working, while matplotlib was a no-op:
   matplotlib/matplotlib#25855

We now mirror this behaviour.

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

Successfully merging a pull request may close this issue.

2 participants