param icon indicating copy to clipboard operation
param copied to clipboard

Should methods on Parameterizeds be treated as references by default

Open MarcSkovMadsen opened this issue 1 year ago • 3 comments

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 avatar Apr 10 '24 07:04 MarcSkovMadsen

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.

philippjfr avatar Apr 10 '24 12:04 philippjfr

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('*'))

maximlt avatar Apr 19 '24 15:04 maximlt

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.

philippjfr avatar Apr 19 '24 15:04 philippjfr