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

IndexError when calling from_param on a Parameter with a negative precedence #3187

Closed
maximlt opened this issue Feb 10, 2022 · 1 comment · Fixed by #3199
Closed

IndexError when calling from_param on a Parameter with a negative precedence #3187

maximlt opened this issue Feb 10, 2022 · 1 comment · Fixed by #3199
Milestone

Comments

@maximlt
Copy link
Member

maximlt commented Feb 10, 2022

Using from_param on a Parameter that has its precedence set to -1 raises an IndexError:

import panel as pn
pn.extension()

class P(param.Parameterized):
    i = param.Integer(default=5, bounds=(1, 10), precedence=-1)
    
    def __init__(self, **params):
        super().__init__(**params)
        widget = pn.widgets.IntSlider.from_param(self.param.i)

p = P()

Traceback:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/tmp/ipykernel_40016/3103289026.py in <module>
      6         widget = pn.widgets.IntSlider.from_param(self.param.i)
      7 
----> 8 p = P()

/tmp/ipykernel_40016/3103289026.py in __init__(self, **params)
      4     def __init__(self, **params):
      5         super().__init__(**params)
----> 6         widget = pn.widgets.IntSlider.from_param(self.param.i)
      7 
      8 p = P()

~/miniconda3/envs/cyber-dev37/lib/python3.7/site-packages/panel/widgets/base.py in from_param(cls, parameter, **params)
     71         from ..param import Param
     72         layout = Param(parameter, widgets={parameter.name: dict(type=cls, **params)})
---> 73         return layout[0]
     74 
     75     def _get_model(self, doc, root=None, parent=None, comm=None):

~/miniconda3/envs/cyber-dev37/lib/python3.7/site-packages/panel/pane/base.py in __getitem__(self, index)
    133         Allows pane objects to behave like the underlying layout
    134         """
--> 135         return self.layout[index]
    136 
    137     #----------------------------------------------------------------

~/miniconda3/envs/cyber-dev37/lib/python3.7/site-packages/panel/layout/base.py in __getitem__(self, index)
    160 
    161     def __getitem__(self, index):
--> 162         return self.objects[index]
    163 
    164     def __len__(self):

IndexError: list index out of range
@jbednar
Copy link
Member

jbednar commented Feb 10, 2022

Makes sense; the Param pane is filtering both by the name specified and by precedence>=0, so the resulting Param pane is empty (no Param matches the given name and has precedence>=0). I think the intention for from_param would be to ignore precedence. e.g. using layout = Param(..., display_threshold=-math.inf).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants