🔍 Code Extractor

function get_param_values

Maturity: 25

Extracts parameter values from a data object, including key dimensions (kdims), value dimensions (vdims), label, and optionally the group if it differs from the default.

File:
/tf/active/vicechatdev/patches/util.py
Lines:
1520 - 1526
Complexity:
simple

Purpose

This function is designed to extract metadata parameters from a data object (likely a HoloViews or similar visualization library object) for the purpose of cloning or recreating objects with the same configuration. It selectively includes the 'group' parameter only when it has been explicitly set to a non-default value and is not a property, making it useful for serialization or object copying scenarios.

Source Code

def get_param_values(data):
    params = dict(kdims=data.kdims, vdims=data.vdims,
                  label=data.label)
    if (data.group != data.param.objects(False)['group'].default and not
        isinstance(type(data).group, property)):
        params['group'] = data.group
    return params

Parameters

Name Type Default Kind
data - - positional_or_keyword

Parameter Details

data: A data object that has attributes 'kdims' (key dimensions), 'vdims' (value dimensions), 'label', 'group', and a 'param' attribute with an 'objects' method. This is typically a HoloViews Element or similar parameterized object that follows the param library conventions.

Return Value

Returns a dictionary containing the extracted parameter values. Always includes 'kdims', 'vdims', and 'label' keys. Conditionally includes 'group' key only if the group value differs from the default and is not a property. The values are direct references to the data object's attributes.

Dependencies

  • param

Required Imports

import param

Usage Example

# Assuming 'data' is a HoloViews Element or similar parameterized object
# Example with a HoloViews Curve object
import param
import holoviews as hv

# Create a sample data object
curve = hv.Curve([1, 2, 3], label='My Curve', group='CustomGroup')

# Extract parameter values
params = get_param_values(curve)

# Result will be a dict like:
# {'kdims': [Dimension('x')], 'vdims': [Dimension('y')], 'label': 'My Curve', 'group': 'CustomGroup'}

# Use the extracted params to create a new object with same configuration
new_curve = hv.Curve([4, 5, 6], **params)

Best Practices

  • Ensure the data object passed has all required attributes (kdims, vdims, label, group, param) before calling this function
  • This function is designed for HoloViews or param-based objects and may not work with arbitrary objects
  • The function performs a conditional check on the 'group' parameter to avoid including default values, which is useful for maintaining clean parameter dictionaries
  • The returned dictionary can be unpacked with ** operator to pass parameters to constructors
  • Be aware that this function returns references to the original attributes, not deep copies

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function unpack_group 52.6% similar

    Unpacks a pandas DataFrame group by iterating over rows and yielding tuples of keys and objects, with special handling for objects with 'kdims' attribute.

    From: /tf/active/vicechatdev/patches/util.py
  • function drop_streams 52.3% similar

    Filters out dimensioned stream parameters from key dimensions (kdims) and their corresponding keys, returning cleaned dimensions and keys.

    From: /tf/active/vicechatdev/patches/util.py
  • function get_spec 50.9% similar

    Extracts a specification tuple from a labeled data object, consisting of the class name, group, and label attributes.

    From: /tf/active/vicechatdev/patches/util.py
  • function dimensionless_contents 50.6% similar

    Filters stream parameters to return only those that are not associated with any of the provided key dimensions.

    From: /tf/active/vicechatdev/patches/util.py
  • function get_unique_keys 50.2% similar

    Extracts unique key values from an ndmapping object for specified dimensions, returning an iterator of unique tuples.

    From: /tf/active/vicechatdev/patches/util.py
← Back to Browse