當前位置: 首頁>>代碼示例>>Python>>正文


Python param.Parameter方法代碼示例

本文整理匯總了Python中param.Parameter方法的典型用法代碼示例。如果您正苦於以下問題:Python param.Parameter方法的具體用法?Python param.Parameter怎麽用?Python param.Parameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在param的用法示例。


在下文中一共展示了param.Parameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process_dynamic_args

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def process_dynamic_args(x, y, kind, **kwds):
    dynamic = {}
    arg_deps = []
    arg_names = []

    for k, v in list(kwds.items()) + [('x', x), ('y', y), ('kind', kind)]:
        if isinstance(v, param.Parameter):
            dynamic[k] = v
        elif panel_available and isinstance(v, pn.widgets.Widget):
            if LooseVersion(pn.__version__) < '0.6.4':
                dynamic[k] = v.param.value
            else:
                dynamic[k] = v

    for k, v in kwds.items():
        if k not in dynamic and isinstance(v, FunctionType) and hasattr(v, '_dinfo'):
            deps = v._dinfo['dependencies']
            arg_deps += list(deps)
            arg_names += list(k) * len(deps)

    return dynamic, arg_deps, arg_names 
開發者ID:holoviz,項目名稱:hvplot,代碼行數:23,代碼來源:util.py

示例2: __call__

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def __call__(self, element, **kwargs):
        params = dict(kwargs)
        for k, v in kwargs.items():
            if util.is_param_method(v, has_deps=True):
                params[k] = v()
            elif isinstance(v, param.Parameter) and isinstance(v.owner, param.Parameterized):
                params[k] = getattr(v.owner, v.name)
        self.p = param.ParamOverrides(self, params,
                                      allow_extra_keywords=self._allow_extra_keywords)
        if not self.p.dynamic:
            kwargs['dynamic'] = False
            if isinstance(element, HoloMap):
                # Backwards compatibility for key argument
                return element.clone([(k, self._apply(el, key=k))
                                      for k, el in element.items()])
            elif ((self._per_element and isinstance(element, Element)) or
                  (not self._per_element and isinstance(element, ViewableElement))):
                return self._apply(element)
        elif 'streams' not in kwargs:
            kwargs['streams'] = self.p.streams
        kwargs['per_element'] = self._per_element
        kwargs['link_dataset'] = self._propagate_dataset
        return element.apply(self, **kwargs) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:25,代碼來源:operation.py

示例3: param_value_if_widget

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def param_value_if_widget(arg):
    if isinstance(arg, Widget):
        return arg.param.value

    from .pane.ipywidget import IPyWidget
    if IPyWidget.applies(arg) and hasattr(arg, 'value'):
        name = type(arg).__name__
        if name in ipywidget_classes:
            ipy_param = ipywidget_classes[name]
        else:
            ipy_param = param.parameterized_class(name, {'value': param.Parameter()})
        ipywidget_classes[name] = ipy_param
        ipy_inst = ipy_param(value=arg.value)
        arg.observe(lambda event: ipy_inst.set_param(value=event['new']), 'value')
        return ipy_inst.param.value
    return arg 
開發者ID:holoviz,項目名稱:panel,代碼行數:18,代碼來源:depends.py

示例4: _validate_object

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def _validate_object(self):
        dependencies = getattr(self.object, '_dinfo', None)
        if not dependencies or not dependencies.get('watch'):
            return
        fn_type = 'method' if type(self) is ParamMethod else 'function'
        self.param.warning(f"The {fn_type} supplied for Panel to display "
                           "was declared with `watch=True`, which will "
                           f"cause the {fn_type} to be called twice for "
                           "any change in a dependent Parameter. "
                           "`watch` should be False when Panel is "
                           "responsible for displaying the result "
                           f"of the {fn_type} call, while `watch=True` "
                           f"should be reserved for {fn_type}s that work "
                           "via side-effects, e.g. by modifying internal  "
                           "state of a class or global state in an "
                           "application's namespace.")

    #----------------------------------------------------------------
    # Callback API
    #---------------------------------------------------------------- 
開發者ID:holoviz,項目名稱:panel,代碼行數:22,代碼來源:param.py

示例5: test_param_subobject_expand_no_toggle

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [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) 
開發者ID:holoviz,項目名稱:panel,代碼行數:19,代碼來源:test_param.py

示例6: test_param_rename

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def test_param_rename():
    "Test that Reactive renames params and properties"

    class ReactiveRename(Reactive):

        a = param.Parameter()
    
        _rename = {'a': 'b'}

    obj = ReactiveRename()

    params = obj._process_property_change({'b': 1})
    assert params == {'a': 1}

    properties = obj._process_param_change({'a': 1})
    assert properties == {'b': 1} 
開發者ID:holoviz,項目名稱:panel,代碼行數:18,代碼來源:test_reactive.py

示例7: define

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def define(cls, name, **kwargs):
        """
        Utility to quickly and easily declare Stream classes. Designed
        for interactive use such as notebooks and shouldn't replace
        parameterized class definitions in source code that is imported.

        Takes a stream class name and a set of keywords where each
        keyword becomes a parameter. If the value is already a
        parameter, it is simply used otherwise the appropriate parameter
        type is inferred and declared, using the value as the default.

        Supported types: bool, int, float, str, dict, tuple and list
        """
        params = {'name': param.String(default=name)}
        for k, v in kwargs.items():
            kws = dict(default=v, constant=True)
            if isinstance(v, param.Parameter):
                params[k] = v
            elif isinstance(v, bool):
                params[k] = param.Boolean(**kws)
            elif isinstance(v, int):
                params[k] = param.Integer(**kws)
            elif isinstance(v, float):
                params[k] = param.Number(**kws)
            elif isinstance(v, str):
                params[k] = param.String(**kws)
            elif isinstance(v, dict):
                params[k] = param.Dict(**kws)
            elif isinstance(v, tuple):
                params[k] = param.Tuple(**kws)
            elif isinstance(v, list):
                params[k] = param.List(**kws)
            elif isinstance(v, np.ndarray):
                params[k] = param.Array(**kws)
            else:
                params[k] = param.Parameter(**kws)

        # Dynamic class creation using type
        return type(name, (Stream,), params) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:41,代碼來源:streams.py

示例8: __init__

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def __init__(self, parameterized=None, parameters=None, watch=True, watch_only=False, **params):
        if util.param_version < '1.8.0' and watch:
            raise RuntimeError('Params stream requires param version >= 1.8.0, '
                               'to support watching parameters.')
        if parameters is None:
            parameters = [parameterized.param[p] for p in parameterized.param if p != 'name']
        else:
            parameters = [p if isinstance(p, param.Parameter) else parameterized.param[p]
                          for p in parameters]

        if 'rename' in params:
            rename = {}
            owners = [p.owner for p in parameters]
            for k, v in params['rename'].items():
                if isinstance(k, tuple):
                    rename[k] = v
                else:
                    rename.update({(o, k): v for o in owners})
            params['rename'] = rename

        self._watch_only = watch_only
        super(Params, self).__init__(parameterized=parameterized, parameters=parameters, **params)
        self._memoize_counter = 0
        self._events = []
        self._watchers = []
        if watch:
            # Subscribe to parameters
            keyfn = lambda x: id(x.owner)
            for _, group in groupby(sorted(parameters, key=keyfn)):
                group = list(group)
                watcher = group[0].owner.param.watch(self._watcher, [p.name for p in group])
                self._watchers.append(watcher) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:34,代碼來源:streams.py

示例9: test_all_stream_parameters_constant

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def test_all_stream_parameters_constant():
    all_stream_cls = [v for v in globals().values() if
                      isinstance(v, type) and issubclass(v, Stream)]
    for stream_cls in all_stream_cls:
        for name, p in stream_cls.param.params().items():
            if name == 'name': continue
            if p.constant != True:
                raise TypeError('Parameter %s of stream %s not declared constant'
                                % (name, stream_cls.__name__)) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:11,代碼來源:teststreams.py

示例10: test_XY_set_invalid_class_y

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def test_XY_set_invalid_class_y(self):
        regexp = "Parameter 'y' only takes numeric values"
        with self.assertRaisesRegexp(ValueError, regexp):
            self.XY.y = 'string' 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:6,代碼來源:teststreams.py

示例11: test_XY_set_invalid_instance_x

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def test_XY_set_invalid_instance_x(self):
        xy = self.XY(x=1,y=2)
        regexp = "Parameter 'x' only takes numeric values"
        with self.assertRaisesRegexp(ValueError, regexp):
            xy.x = 'string' 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:7,代碼來源:teststreams.py

示例12: test_XY_set_invalid_instance_y

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def test_XY_set_invalid_instance_y(self):
        xy = self.XY(x=1,y=2)
        regexp = "Parameter 'y' only takes numeric values"
        with self.assertRaisesRegexp(ValueError, regexp):
            xy.y = 'string' 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:7,代碼來源:teststreams.py

示例13: params

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def params(self):
        params = {}
        for op in self.ops:
            op_args = list(op['args'])+list(op['kwargs'].values())
            for op_arg in op_args:
                if 'panel' in sys.modules:
                    from panel.widgets.base import Widget
                    if isinstance(op_arg, Widget):
                        op_arg = op_arg.param.value
                if (isinstance(op_arg, param.Parameter) and
                    isinstance(op_arg.owner, param.Parameterized)):
                    params[op_arg.name+str(id(op))] = op_arg
        return params

    # Namespace properties 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:17,代碼來源:transform.py

示例14: _update_backend

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def _update_backend(cls, backend):

        if cls.__original_docstring__ is None:
            cls.__original_docstring__ = cls.__doc__

        all_keywords = set()
        element_keywords = cls._element_keywords(backend)
        for element, keywords in element_keywords.items():
            with param.logging_level('CRITICAL'):
                all_keywords |= set(keywords)
                setattr(cls, element,
                        cls._create_builder(element, keywords))

        filtered_keywords = [k for k in all_keywords if k not in cls._no_completion]
        sorted_kw_set = sorted(set(filtered_keywords))
        if sys.version_info.major == 2:
            kws = ', '.join('{opt}=None'.format(opt=opt) for opt in sorted_kw_set)
            old_doc = cls.__original_docstring__.replace(
                'params(strict=Boolean, name=String)','')
            cls.__doc__ = '\n    opts({kws})'.format(kws=kws) + old_doc
        else:
            from inspect import Parameter, Signature
            signature = Signature([Parameter('args', Parameter.VAR_POSITIONAL)]
                                  + [Parameter(kw, Parameter.KEYWORD_ONLY)
                                     for kw in sorted_kw_set])
            cls.__init__.__signature__ = signature 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:28,代碼來源:__init__.py

示例15: resolve_dependent_value

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameter [as 別名]
def resolve_dependent_value(value):
    """Resolves parameter dependencies on the supplied value

    Resolves parameter values, Parameterized instance methods and
    parameterized functions with dependencies on the supplied value.

    Args:
       value: A value which will be resolved

    Returns:
       A new dictionary where any parameter dependencies have been
       resolved.
    """
    if 'panel' in sys.modules:
        from panel.widgets.base import Widget
        if isinstance(value, Widget):
            value = value.param.value
    if is_param_method(value, has_deps=True):
        value = value()
    elif isinstance(value, param.Parameter) and isinstance(value.owner, param.Parameterized):
        value = getattr(value.owner, value.name)
    elif isinstance(value, FunctionType) and hasattr(value, '_dinfo'):
        deps = value._dinfo
        args = (getattr(p.owner, p.name) for p in deps.get('dependencies', []))
        kwargs = {k: getattr(p.owner, p.name) for k, p in deps.get('kw', {}).items()}
        value = value(*args, **kwargs)
    return value 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:29,代碼來源:util.py


注:本文中的param.Parameter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。