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

NameError: name 'FloatSlider' is not defined when using widgets.py without ipywidgets installed #3755

Open
mrapacz opened this issue Aug 29, 2024 · 1 comment

Comments

@mrapacz
Copy link

mrapacz commented Aug 29, 2024

I'm running the latest seaborn (0.13.2) on Mac OS 14.2.1 (x86_64), Python 3.12.4.

The issue

When a user attempts to use widgets from widgets.py module without having ipywidgets installed, the intended ImportError is not raised because of a NameError raised moments before that.

Steps to reproduce:

1. Set up a fresh virtualenv.
$ pip freeze
setuptools==72.1.0
wheel==0.43.0
2. Install seaborn (skip ipywidgets).
$ pip install seaborn
...
$ pip freeze
contourpy==1.2.1
cycler==0.12.1
fonttools==4.53.1
kiwisolver==1.4.5
matplotlib==3.9.2
numpy==2.0.1
packaging==24.1
pandas==2.2.2
pillow==10.4.0
pyparsing==3.1.2
python-dateutil==2.9.0.post0
pytz==2024.1
seaborn==0.13.2
setuptools==72.1.0
six==1.16.0
tzdata==2024.1
wheel==0.43.0
  1. Attempt to use one of the colormap widgets.
$ python -c "import seaborn; seaborn.choose_colorbrewer_palette('quatlitative')"                                                                                                                                                                  (test-seaborn-fresh)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<redacted>/anaconda3/envs/test-seaborn-setup/lib/python3.12/site-packages/seaborn/widgets.py", line 134, in choose_colorbrewer_palette
    desat=FloatSlider(min=0, max=1, value=1)):
          ^^^^^^^^^^^
NameError: name 'FloatSlider' is not defined

Root cause

The widgets.py module wraps imports from ipywidgets with a try/except clause (link). When the user doesn't have ipywidgets installed, the interact function is patched to raise an ImportError and notify the user on the missing module upon invocation.

The local functions defined later in the module are guarded using the wrapper:

@interact
def choose_sequential(name=opts, n=(2, 18),
    desat=FloatSlider(min=0, max=1, value=1),
    variant=variants):

Unfortunately, such function definitions already attempt to use the members of the ipywidgets module to define the default values for parameters (in this case the FloatSlider is used to define a default for desat). This prevents the user from seeing the intended ImportError and presents them with a NameError instead like the one reproduced above.

@mrapacz
Copy link
Author

mrapacz commented Aug 29, 2024

Ι've suggested a PR addressing the issue - #3747

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

No branches or pull requests

1 participant