mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.6k stars 1.93k forks source link

Fix: Add dummy widgets to suppress NameError and warn about missing ipywidgets #3747

Open mrapacz opened 3 months ago

mrapacz commented 3 months ago

This addresses #3755

Resolution

This PR fixes the issue by defining dummy FloatSlider and IntSlider classes which do not raise exceptions when instantiated. This allows the patched @interact to handle the missing ipywidgets scenario gracefully.

After applying the changes suggested in this PR the ImportError is raised as intended.

$ python -c "import seaborn; seaborn.choose_colorbrewer_palette('quatlitative')"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<redacted>/seaborn/seaborn/widgets.py", line 141, in choose_colorbrewer_palette
    @interact
     ^^^^^^^^
  File "<redacted>/seaborn/seaborn/widgets.py", line 10, in interact
    raise ImportError(msg)
ImportError: Interactive palettes require `ipywidgets`, which is not installed.