RecursionError in `param` class instantiation

Hi everyone, I was just struggling for a couple of hours with a RecursionError in the my param class. I thought I’d be interesting to share my experience. :slight_smile: In the following code you can find a minimal working example showing which fails to work:

import panel as pn
import param
import hvplot.pandas
import pandas as pd
import numpy as np
import holoviews as hv

df_all = pd.DataFrame(data=np.random.normal(size=100).cumsum(),columns=['col1'])

class Flex_datas(param.Parameterized):
    df = param.DataFrame(default=df_all)
    col1 = pn.widgets.RangeSlider(name='col1',start=df_all.col1.min(),end=df_all.col1.max())
    def __init__(self,**params):
        self.layout = pn.Row(self.col1,self.view)
    def view(self):
        querystring = f'col1>{self.col1.value[0]} & col1<{self.col1.value[1]}'
        self.df = df_all.query(querystring)
        return hv.Layout([self.df.hvplot.scatter(y=col,label=col) for col in self.df.columns])
f = Flex_datas()


Eventually, by constructing the minimal example above, I was able to figure out what was going on…

1 Like

The solution is in the @pn.depends('col1') line.
The code seems to accept the pn.widget.RangeSlider name as argument, but it ignores the line entirely. As a consequence I guess the default behaviour for param methods without a @pn.depends decorator is active: the method gets called whenever any parameter of the class changes, which in my code is the update of self.df, hence infinite recursion.

Since col1 is a panel widget and not a param.Parameter, what I should’ve written is:

def view(self)

Now it works:

But in general I would expect @pn.depends('col1') throws an error, similarly to what it does when using other incorrect arguments. Is there a reason to accept widget objects?
And even if col1 updates are ignored, I would expect that adding @pn.depends('col1') prevents the default param method behavior: being called when any parameter changes?

Kind regards!