Open phi6ias opened 1 year ago
Thanks for the issue report, I can indeed reproduce it with this simplified version:
import param
class Other(param.Parameterized):
x = param.Integer(1)
other = Other()
class P(param.Parameterized):
other = param.Parameter(other)
def __init__(self, **params):
super().__init__(**params)
self.param.watch(self.debug, ['other.x'])
def debug(self, *events):
print('DEBUG')
p = P()
Traceback:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[118], line 20
17 def debug(self, *events):
18 print('DEBUG')
---> 20 p = P()
Cell In[118], line 15, in P.__init__(self, **params)
13 def __init__(self, **params):
14 super().__init__(**params)
---> 15 self.param.watch(self.debug, ['other.x'])
File ~/dev/param/param/parameterized.py:2454, in Parameters.watch(self_, fn, parameter_names, what, onlychanged, queued, precedence)
2450 if precedence < 0:
2451 raise ValueError("User-defined watch callbacks must declare "
2452 "a positive precedence. Negative precedences "
2453 "are reserved for internal Watchers.")
-> 2454 return self_._watch(fn, parameter_names, what, onlychanged, queued, precedence)
File ~/dev/param/param/parameterized.py:2461, in Parameters._watch(self_, fn, parameter_names, what, onlychanged, queued, precedence)
2457 parameter_names = tuple(parameter_names) if isinstance(parameter_names, list) else (parameter_names,)
2458 watcher = Watcher(inst=self_.self, cls=self_.cls, fn=fn, mode='args',
2459 onlychanged=onlychanged, parameter_names=parameter_names,
2460 what=what, queued=queued, precedence=precedence)
-> 2461 self_._register_watcher('append', watcher, what)
2462 return watcher
File ~/dev/param/param/parameterized.py:2396, in Parameters._register_watcher(self_, action, watcher, what)
2394 for parameter_name in parameter_names:
2395 if parameter_name not in self_.cls.param:
-> 2396 raise ValueError("%s parameter was not found in list of "
2397 "parameters of class %s" %
2398 (parameter_name, self_.cls.__name__))
2400 if self_.self is not None and what == "value":
2401 watchers = self_.self._param_watchers
ValueError: other.x parameter was not found in list of parameters of class P
Hi @maximlt
what I did find out in the meantime is that defining the watch on the objects param instead of the class param does work. I don't know if that is the intended behaviour, which is more for you to decide.
import param
class Other(param.Parameterized):
x = param.Integer(1)
other = Other()
class P(param.Parameterized):
other_ = param.Parameter(other)
def __init__(self, **params):
super().__init__(**params)
self.other_.param.watch(self.debug, ['x'])
def debug(self, *events):
print('DEBUG')
p = P()
other.x=2
ALL software version info
param 1.12.2
run in powershell prompt using panel serve running Bokeh server 2.4.3 on Tornado 6.2
run in VS Code jupyter notebook Version: 1.76.2 (user setup) Commit: ee2b180d582a7f601fa6ecfdad8d9fd269ab1884 Date: 2023-03-14T17:55:54.936Z Electron: 19.1.11 Chromium: 102.0.5005.196 Node.js: 16.14.2 V8: 10.2.154.26-electron.0 OS: Windows_NT x64 10.0.19045 Sandboxed: No
Description of expected behavior and the observed behavior
When using the decorator @param.depends() it is possible to use a parameter from another class that is stored as a Parameterized instance in the current class, similar as described in this thread --> Holoviz Discourse: Shared Parameter? However, trying the same with the lower-level self.param.watch() yields an error message.
In the example below, the decorated function works, while the param.watched throws an error on executing the cell comprising
anB = Bclass(otherclass=anA)
. If the "param.watch'ed" function is changed to a decorated, then again everything works fine.Am I missing something? Should the behaviour not be the same?
Complete, minimal, self-contained example code that reproduces the issue
Stack traceback and/or browser JavaScript console output
Screenshots or screencasts of the bug in action