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

'NumberInput' has no attribute 'param' #1708

Closed
sdc50 opened this issue Oct 27, 2020 · 1 comment · Fixed by #1709
Closed

'NumberInput' has no attribute 'param' #1708

sdc50 opened this issue Oct 27, 2020 · 1 comment · Fixed by #1709
Milestone

Comments

@sdc50
Copy link
Contributor

sdc50 commented Oct 27, 2020

Starting with panel version 0.10.0a28, when trying to substitute the default widget for a param.Integer with another widget (e.g. pn.widgets.Spinner or pn.widgets.NumberInput) I get the following error:

AttributeError: type object 'NumberInput' has no attribute 'param'

bokeh=2.2.3
param=1.10.0

The following code works with panel=0.10.0a27, but produces an error in all releases starting with panel=0.10.0a28 (including 0.10.0).

class Test(param.Parameterized):
    a = param.Integer(default=1, bounds=(1,10))

    def panel(self):
        return pn.panel(
            self,
            widgets={'a': pn.widgets.Spinner},
        )
t = Test()
t.panel()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-b87b7a79b9d9> in <module>
      8         )
      9 t = Test()
---> 10 t.panel()

<ipython-input-6-b87b7a79b9d9> in panel(self)
      3 
      4     def panel(self):
----> 5         return pn.panel(
      6             self,
      7             widgets={'a': pn.widgets.NumberInput},

~/miniconda/envs/uit/lib/python3.9/site-packages/panel/pane/base.py in panel(obj, **kwargs)
     49     if kwargs.get('name', False) is None:
     50         kwargs.pop('name')
---> 51     pane = PaneBase.get_pane_type(obj, **kwargs)(obj, **kwargs)
     52     if len(pane.layout) == 1 and pane._unpack:
     53         return pane.layout[0]

~/miniconda/envs/uit/lib/python3.9/site-packages/panel/param.py in __init__(self, object, **params)
    189             'object', 'parameters', 'name', 'display_threshold', 'expand_button',
    190             'expand', 'expand_layout', 'widgets', 'show_labels', 'show_name'])
--> 191         self._update_widgets()
    192 
    193     def __repr__(self, depth=0):

~/miniconda/envs/uit/lib/python3.9/site-packages/panel/param.py in _update_widgets(self, *events)
    258             self._widgets = {}
    259         else:
--> 260             self._widgets = self._get_widgets()
    261 
    262         alias = {'_title': 'name'}

~/miniconda/envs/uit/lib/python3.9/site-packages/panel/param.py in _get_widgets(self)
    528         else:
    529             widgets = []
--> 530         widgets += [(pname, self.widget(pname)) for pname in self._ordered_params]
    531         return OrderedDict(widgets)
    532 

~/miniconda/envs/uit/lib/python3.9/site-packages/panel/param.py in <listcomp>(.0)
    528         else:
    529             widgets = []
--> 530         widgets += [(pname, self.widget(pname)) for pname in self._ordered_params]
    531         return OrderedDict(widgets)
    532 

~/miniconda/envs/uit/lib/python3.9/site-packages/panel/param.py in widget(self, p_name)
    390                 kw['step'] = p_obj.step
    391 
--> 392         kwargs = {k: v for k, v in kw.items() if k in widget_class.param}
    393 
    394         if isinstance(widget_class, Widget):

~/miniconda/envs/uit/lib/python3.9/site-packages/panel/param.py in <dictcomp>(.0)
    390                 kw['step'] = p_obj.step
    391 
--> 392         kwargs = {k: v for k, v in kw.items() if k in widget_class.param}
    393 
    394         if isinstance(widget_class, Widget):

AttributeError: type object 'NumberInput' has no attribute 'param'
@philippjfr
Copy link
Member

Thanks @sdc50! The problem is that NumberInput basically just defers to IntInput and FloatInput. An easy fix here is to just make it a subclass of _SpinnerBase though.

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