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

Confusing error from hv.opts prior to hv.extension() #5463

Closed
jbednar opened this issue Sep 30, 2022 · 5 comments · Fixed by #5494
Closed

Confusing error from hv.opts prior to hv.extension() #5463

jbednar opened this issue Sep 30, 2022 · 5 comments · Fixed by #5494
Assignees
Labels
TRIAGE Needs triaging

Comments

@jbednar
Copy link
Member

jbednar commented Sep 30, 2022

Current published and master versions of HoloViews give a bewildering error when trying to create element-specific options objects:

image

hv.opts apparently only populates its various accessors when hv.extension loads, but the error message doesn't convey anything to me about "run hv.extension()". I've encountered this issue several times over the years, usually when I'm trying to isolate some code that (in my mind) has nothing to do with a particular backend. Each time I get completely sidetracked -- I'm trying to debug one thing, and now suddenly I can't even set an option on hv.opts.Image? It's particularly a problem in a Jupyter notebook, when I restart the kernel, then try to look at a tiny bit of code that has nothing to do with actual plotting, and suddenly things like this don't work. Eventually I do figure out that it's because hv.extension needs to be run, but each time I've now wasted a good bit of time.

Is there a way that instead of failing with this obscure message, instead it could print something helpful, like "No subobject of type Image has been registered; maybe you need to run hv.extension to declare a plotting backend?"?

@jbednar jbednar added the TRIAGE Needs triaging label Sep 30, 2022
@hoxbro
Copy link
Member

hoxbro commented Oct 14, 2022

A way to get a better message is with a metaclass:

import param
from param.parameterized import ParameterizedMetaclass


class OptsMeta(ParameterizedMetaclass):
    def __getattr__(self, attr):
        try:
            return super().__getattr__(attr)
        except AttributeError:
            msg = f"No subobject of type {attr} has been registered; maybe you need to run 'hv.extension' to declare a plotting backend?"
            raise AttributeError(msg) from None


class opts(param.ParameterizedFunction, metaclass=OptsMeta):
    pass

image

@jbednar
Copy link
Member Author

jbednar commented Oct 14, 2022

Sounds good to me! @jlstevens ?

@jlstevens
Copy link
Contributor

jlstevens commented Oct 14, 2022

Yes, I like this metaclass approach!

The message is good but wouldn't it appear for other missing attributes, e.g. due to typos (opts.Curvve).

I think a better message might be:

No entry for 'Curve' registered; this name may not refer to a valid object 
or you may need to run `hv.extension` to select a plotting backend.

Would be happy to merge a PR using this approach/message.

@jbednar
Copy link
Member Author

jbednar commented Oct 14, 2022

Good point; sounds good.

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
TRIAGE Needs triaging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants