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

Make hv.Cycle KeyError text more helpful or read keys for hv.Cycle automatically #5238

Closed
fohrloop opened this issue Mar 17, 2022 · 1 comment · Fixed by #5379
Closed

Make hv.Cycle KeyError text more helpful or read keys for hv.Cycle automatically #5238

fohrloop opened this issue Mar 17, 2022 · 1 comment · Fixed by #5379

Comments

@fohrloop
Copy link

fohrloop commented Mar 17, 2022

Using: Holoviews 1.14.8

Is your feature request related to a problem? Please describe.

When following some examples from the internet, there might be a point where hv.Cycle is used. Usage of it needs import with side effects. Without any imports, user will see:

In [1]: import holoviews as hv
   ...: hv.Cycle("Set1")
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Input In [1], in <module>
      1 import holoviews as hv
----> 2 hv.Cycle("Set1")

File c:\python\venvs\myproj\lib\site-packages\holoviews\core\options.py:325, in Cycle.__init__(self, cycle, **params)
    323         params['key'] = None
    324 super(Cycle, self).__init__(**params)
--> 325 self.values = self._get_values()

File c:\python\venvs\myproj\lib\site-packages\holoviews\core\options.py:335, in Cycle._get_values(self)
    333 if self.values: return self.values
    334 elif self.key:
--> 335     return list(self.default_cycles[self.key])
    336 else:
    337     raise ValueError("Supply either a key or explicit values.")

KeyError: 'Set1'

While the following works (as calling hv.extension has a side effect that is needed for hv.Cycle):

In [1]: import holoviews as hv
   ...: hv.extension()
   ...:
   ...: hv.Cycle("Set1")
Out[1]: Cycle('Set1')

Describe the solution you'd like

Instead of printing

KeyError: 'Set1'

print

KeyError: 'Set1'. Did you forget to call panel.extension?

Describe alternatives you've considered

Another possibility could be to call hv.extension, or somehow else fetch the default list of keys for hv.Cycle, in case of error.


Edit: replaced pn.extension with hv.extension.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant