本文整理汇总了Python中param.Parameterized方法的典型用法代码示例。如果您正苦于以下问题:Python param.Parameterized方法的具体用法?Python param.Parameterized怎么用?Python param.Parameterized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类param
的用法示例。
在下文中一共展示了param.Parameterized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_params
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def from_params(cls, params, **kwargs):
"""Returns Params streams given a dictionary of parameters
Args:
params (dict): Dictionary of parameters
Returns:
List of Params streams
"""
key_fn = lambda x: id(x[1].owner)
streams = []
for _, group in groupby(sorted(params.items(), key=key_fn), key_fn):
group = list(group)
inst = [p.owner for _, p in group][0]
if not isinstance(inst, param.Parameterized):
continue
names = [p.name for _, p in group]
rename = {p.name: n for n, p in group}
streams.append(cls(inst, names, rename=rename, **kwargs))
return streams
示例2: test_deep_apply_parameterized_method_with_dependency
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_deep_apply_parameterized_method_with_dependency(self):
class Test(param.Parameterized):
label = param.String(default='label')
@param.depends('label')
def relabel(self, obj):
return obj.relabel(self.label.title())
test = Test()
fn = lambda i: Curve(np.arange(i))
dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
mapped = dmap.apply(test.relabel)
curve = fn(10)
self.assertEqual(mapped[10], curve.relabel('Label'))
test.label = 'new label'
self.assertEqual(mapped[10], curve.relabel('New Label'))
示例3: test_deep_apply_parameterized_method_with_dependency_and_static_kwarg
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_deep_apply_parameterized_method_with_dependency_and_static_kwarg(self):
class Test(param.Parameterized):
label = param.String(default='label')
@param.depends('label')
def relabel(self, obj, group):
return obj.relabel(self.label.title(), group)
test = Test()
fn = lambda i: Curve(np.arange(i))
dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
mapped = dmap.apply(test.relabel, group='Group')
curve = fn(10)
self.assertEqual(mapped[10], curve.relabel('Label', 'Group'))
test.label = 'new label'
self.assertEqual(mapped[10], curve.relabel('New Label', 'Group'))
示例4: is_param_method
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def is_param_method(obj, has_deps=False):
"""Whether the object is a method on a parameterized object.
Args:
obj: Object to check
has_deps (boolean, optional): Check for dependencies
Whether to also check whether the method has been annotated
with param.depends
Returns:
A boolean value indicating whether the object is a method
on a Parameterized object and if enabled whether it has any
dependencies
"""
parameterized = (inspect.ismethod(obj) and
isinstance(get_method_owner(obj), param.Parameterized))
if parameterized and has_deps:
return getattr(obj, "_dinfo", {}).get('dependencies')
return parameterized
示例5: disable_constant
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def disable_constant(parameterized):
"""
Temporarily set parameters on Parameterized object to
constant=False.
"""
params = parameterized.param.objects('existing').values()
constants = [p.constant for p in params]
for p in params:
p.constant = False
try:
yield
except:
raise
finally:
for (p, const) in zip(params, constants):
p.constant = const
示例6: __call__
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def __call__(self, obj, filter_fn=None):
if filter_fn is None:
return obj
name = obj.__name__ if isinstance(obj,type) else obj.__class__.__name__
class_proxy = type(name, (param.Parameterized,),
{k:v for k,v in obj.param.objects('existing').items()
if filter_fn(k,v)})
if isinstance(obj,type):
return class_proxy
else:
instance_params = obj.param.get_param_values()
obj_proxy = class_proxy()
filtered = {k:v for k,v in instance_params
if (k in obj_proxy.param)
and not obj_proxy.param.objects('existing')[k].constant}
obj_proxy.param.set_param(**filtered)
return obj_proxy
示例7: edit_readonly
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def edit_readonly(parameterized):
"""
Temporarily set parameters on Parameterized object to readonly=False
to allow editing them.
"""
params = parameterized.param.objects("existing").values()
readonlys = [p.readonly for p in params]
constants = [p.constant for p in params]
for p in params:
p.readonly = False
p.constant = False
try:
yield
except Exception:
raise
finally:
for (p, readonly) in zip(params, readonlys):
p.readonly = readonly
for (p, constant) in zip(params, constants):
p.constant = constant
示例8: test_widget_from_param_instance_with_kwargs
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_widget_from_param_instance_with_kwargs():
class Test(param.Parameterized):
a = param.Number(default=3.14)
test = Test()
widget = FloatSlider.from_param(test.param.a, start=0.3, end=5.2)
assert isinstance(widget, FloatSlider)
assert widget.name == 'A'
assert widget.start == 0.3
assert widget.end == 5.2
assert widget.value == 3.14
test.a = 1.57
assert widget.value == 1.57
widget.value = 4.3
assert test.a == 4.3
示例9: test_action_param
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_action_param(document, comm):
class Test(param.Parameterized):
a = param.Action(lambda x: setattr(x, 'b', 2))
b = param.Number(default=1)
test = Test()
test_pane = Pane(test)
model = test_pane.get_root(document, comm=comm)
button = model.children[1]
assert isinstance(button, Button)
# Check that the action is actually executed
pn_button = test_pane.layout[1]
pn_button.clicks = 1
assert test.b == 2
示例10: test_set_name
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_set_name(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10))
b = param.String(default='A')
pane = Param(Test(), name='First')
model = pane.get_root(document, comm=comm)
assert len(model.children) == 3
title, slider, text = model.children
assert isinstance(title, Div)
# Check setting name displays in as a title
assert title.text == '<b>First</b>'
assert isinstance(slider, Slider)
assert isinstance(text, TextInput)
pane.name = 'Second'
assert len(model.children) == 3
title, _, _ = model.children
assert isinstance(title, Div)
# Check the title updates with name
assert title.text == '<b>Second</b>'
示例11: test_set_parameters
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_set_parameters(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10))
b = param.String(default='A')
pane = Param(Test())
model = pane.get_root(document, comm=comm)
assert len(model.children) == 3
title, slider, text = model.children
assert isinstance(title, Div)
assert isinstance(slider, Slider)
assert isinstance(text, TextInput)
pane.parameters = ['b']
assert len(model.children) == 2
title, text = model.children
assert isinstance(title, Div)
assert isinstance(text, TextInput)
示例12: test_set_show_name
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_set_show_name(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10))
pane = Param(Test())
model = pane.get_root(document, comm=comm)
assert len(model.children) == 2
title, widget = model.children
assert isinstance(title, Div)
assert isinstance(widget, Slider)
pane.show_name = False
assert len(model.children) == 1
assert isinstance(model.children[0], Slider)
示例13: test_set_show_labels
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_set_show_labels(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10))
pane = Param(Test())
model = pane.get_root(document, comm=comm)
assert len(model.children) == 2
title, widget = model.children
assert isinstance(title, Div)
assert isinstance(widget, Slider)
assert widget.title == 'A'
pane.show_labels = False
assert len(model.children) == 2
assert isinstance(model.children[1], Slider)
assert model.children[1].title == ''
示例14: test_expand_param_subobject_expand
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_expand_param_subobject_expand(document, comm):
class Test(param.Parameterized):
a = param.Parameter()
test = Test(a=Test(name='Nested'))
test_pane = Pane(test, expand=True, expand_button=True)
model = test_pane.get_root(document, comm=comm)
toggle = model.children[1].children[1]
assert isinstance(toggle, Toggle)
# Expand subpane
assert len(model.children) == 3
_, _, subpanel = test_pane.layout.objects
col = model.children[2]
assert isinstance(col, BkColumn)
assert len(col.children) == 2
div, widget = col.children
assert div.text == '<b>Nested</b>'
assert isinstance(widget, BkTextInput)
# Collapse subpanel
test_pane._widgets['a'][1].value = False
assert len(model.children) == 2
assert subpanel._models == {}
示例15: test_param_subobject_expand_no_toggle
# 需要导入模块: import param [as 别名]
# 或者: from param import Parameterized [as 别名]
def test_param_subobject_expand_no_toggle(document, comm):
class Test(param.Parameterized):
a = param.Parameter()
test = Test(a=Test(name='Nested'))
test_pane = Pane(test, expand=True,
expand_button=False)
model = test_pane.get_root(document, comm=comm)
# Assert no toggle was added
assert len(model.children) == 3
# Expand subpane
_, _, subpanel = test_pane.layout.objects
div, widget = model.children[2].children
assert div.text == '<b>Nested</b>'
assert isinstance(widget, BkTextInput)