function unbound_dimensions
Filters a list of dimensions (kdims) to return only those that have not been associated with any of the provided streams.
/tf/active/vicechatdev/patches/util.py
1757 - 1763
simple
Purpose
This function is used to identify which dimensions in a visualization or data structure remain unbound to stream parameters. It's particularly useful in dynamic plotting libraries (like HoloViews) where streams control interactive parameters, and you need to know which dimensions are still available for other purposes or need to be bound. The function helps manage the relationship between data dimensions and interactive stream parameters.
Source Code
def unbound_dimensions(streams, kdims, no_duplicates=True):
"""
Return a list of dimensions that have not been associated with
any streams.
"""
params = stream_parameters(streams, no_duplicates)
return [d for d in kdims if d not in params]
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
streams |
- | - | positional_or_keyword |
kdims |
- | - | positional_or_keyword |
no_duplicates |
- | True | positional_or_keyword |
Parameter Details
streams: A collection (likely list or iterable) of stream objects that contain parameters. These streams represent interactive or dynamic data sources that have been associated with certain dimensions.
kdims: A list or iterable of dimension objects (key dimensions) that need to be checked for stream associations. These represent the dimensions of the data or visualization that may or may not be bound to streams.
no_duplicates: Boolean flag (default: True) that controls whether duplicate parameters should be removed when extracting parameters from streams. When True, ensures each parameter is counted only once across all streams.
Return Value
Returns a list of dimension objects from kdims that are not present in the parameters extracted from the provided streams. These are the 'unbound' dimensions that have not been associated with any stream parameter. The return type is a list containing dimension objects of the same type as those in the input kdims parameter.
Dependencies
stream_parameters
Required Imports
from <module_containing_stream_parameters> import stream_parameters
Usage Example
# Assuming stream_parameters function is available and appropriate stream/dimension classes exist
# Example with hypothetical Stream and Dimension classes
from holoviews.streams import Stream, PointerX
from holoviews.core.dimension import Dimension
# Create some dimensions
x_dim = Dimension('x')
y_dim = Dimension('y')
z_dim = Dimension('z')
all_dims = [x_dim, y_dim, z_dim]
# Create streams that bind to some dimensions
stream1 = PointerX(x='x') # Binds to x dimension
streams = [stream1]
# Find unbound dimensions
unbound = unbound_dimensions(streams, all_dims, no_duplicates=True)
# Result: [y_dim, z_dim] - dimensions not associated with any stream
print(f"Unbound dimensions: {[d.name for d in unbound]}")
# Output: Unbound dimensions: ['y', 'z']
Best Practices
- Ensure that the stream_parameters function is properly imported and available in the scope
- The dimension objects in kdims should be comparable (implement __eq__ and __hash__) for proper membership testing
- Set no_duplicates=True (default) when you want to avoid counting the same parameter multiple times across different streams
- This function performs a simple list comprehension filter, so it's efficient for small to moderate numbers of dimensions
- The function assumes that stream_parameters returns an iterable that can be used with the 'in' operator for membership testing
- Consider the order of dimensions in kdims if order matters for downstream processing, as the function preserves the original order
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function dimensionless_contents 78.8% similar
-
function drop_streams 78.4% similar
-
function dimensioned_streams 74.2% similar
-
function wrap_tuple_streams 54.0% similar
-
function get_nested_streams 51.7% similar