Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support positional stream args in DynamicMap callback #4534

Merged
merged 6 commits into from
Aug 14, 2020

Conversation

jonmmease
Copy link
Collaborator

This PR is a step toward supporting #4433 using a DynamicMap transformation. The idea is described in #4433 (comment).

Background

The callback function for a DynamicMap is currently called by passing the kdim values as positional arguments, followed by stream parameter values as keyword arguments. For example:

import holoviews as hv
from holoviews.streams import Stream
XY = Stream.define('XY', x=0,y=0)
xy_stream = XY()

def callback_fn(i_value, y, x):
    ...

dmap = hv.DynamicMap(callback_fn, kdims=["i"], streams=[xy_stream])

Here the i_value argument is the i key dimension that is called positionally (named i_value to emphasize that it's called by position not by name), and the x and y arguments are the stream parameters and they are called as keyword arguments. So here the x and y argument names must match the param names of the xy_stream stream.

This approach is convenient when writing callback functions by hand, when there are only a few stream parameters and the stream parameter names don't conflict. But it's less convenience when building a callback function programmatically that will input many streams with potentially overlapping parameter names. This will be the situation when building the transformation in #4433.

Description

This PR adds a positional_stream_args parameter to the DynamicMap class that, when set to True, will configure the DynamicMap to pass stream values to the callback function positionally. The stream arguments will follow the kdim arguments (if any), the value of each stream argument is a dict containing key-value pairs for each param in the stream, and the order of the stream arguments is determined by the order of the streams in the streams parameter list.

Here's an example of what this looks like:

import holoviews as hv
from holoviews.streams import Stream
XY = Stream.define('XY', x=0,y=0)
xy_stream0 = XY()
xy_stream1 = XY()

def callback_fn(i_value, s0, s1):
    x0, y0 = s0['x'], s0['y']
    x1, y1 = s1['x'], s1['y']
    ...

dmap = hv.DynamicMap(
    callback_fn, kdims=["i"], streams=[xy_stream0, yx_stream1], positional_stream_args=True
)

When positional_stream_args=True there is no possibility of stream parameter name clashes.

Of course, the default is False to match the current behavior.

Does this sound reasonable @jlstevens @philippjfr ?

to accept stream values as positional arg dictionaries in DynamicMap callbacks.
@philippjfr
Copy link
Member

The changes look fine to me, but I'll try to fix the tests before merging.

@jonmmease
Copy link
Collaborator Author

Ok, updated with master and tests are passing. Anything else come to mind for this PR @philippjfr?

@jonmmease
Copy link
Collaborator Author

@philippjfr alright if we merge this today?

@philippjfr
Copy link
Member

Yes, looks good to me.

@philippjfr philippjfr merged commit f1e225d into master Aug 14, 2020
@jonmmease
Copy link
Collaborator Author

Thanks a lot @philippjfr!

@philippjfr philippjfr deleted the positional_stream_args branch April 25, 2022 14:39
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants