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

Should methods on Parameterizeds be treated as references by default #936

Open
MarcSkovMadsen opened this issue Apr 10, 2024 · 3 comments
Open
Labels
status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues.

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Apr 10, 2024

panel==1.4.1

When using a parameterized class methods that are not explicitly annotated with .depends my understanding is that they implicitly depend on all class parameters. Thus I should be able to use them as references just as methods marked with .depends.

I cannot when using Tabulator.

import panel as pn
import param
import pandas as pd

pn.extension()


class CustomComponent(pn.viewable.Viewer):
    value = param.Integer(default=2, bounds=(1,10))

    # @param.depends("value")
    def data(self):
        return pd.DataFrame({"x": [self.value]*self.value})

    def __panel__(self):
        return pn.Column(
            self.param.value,
            pn.widgets.Tabulator(self.data, pagination="remote", page_size=10)
        )

pn.extension("tabulator")
CustomComponent().servable()

image

It works without the using Tabulator or if I .depends on the value.

@MarcSkovMadsen MarcSkovMadsen changed the title AttributeError: 'function' object has no attribute 'index' Cannot use method of Parameterized class as reference with Tabulator Apr 10, 2024
@philippjfr philippjfr transferred this issue from holoviz/panel Apr 10, 2024
@philippjfr philippjfr changed the title Cannot use method of Parameterized class as reference with Tabulator Should methods on Parameterizeds be treated as references by default Apr 10, 2024
@philippjfr philippjfr added the status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues. label Apr 10, 2024
@philippjfr
Copy link
Member

Reference resolution happens at the param level so I've transferred this for now and marked it as a discussion point. @MarcSkovMadsen is correct that in other scenarios we do treated un-annotated methods as if they depended on all parameters so making them valid references would be consistent.

@maximlt
Copy link
Member

maximlt commented Apr 19, 2024

in other scenarios we do treated un-annotated methods as if they depended on all parameters

Does anyone remember the rationale for this behavior? (I'd rather have to type something explicit like param.depends('*'))

@philippjfr
Copy link
Member

Does anyone remember the rationale for this behavior?

Yes, @jbednar strongly argued that it would be easy to forget to declare the dependencies so this was the safe default behavior. I've wavered on this in the past but think generally it was the right default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues.
Projects
None yet
Development

No branches or pull requests

3 participants