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

Add functionality to stream from parameterized objects and methods #2961

Merged
merged 8 commits into from Aug 30, 2018

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Aug 27, 2018

Requires holoviz/param#253 to work

  • Adds ability to directly stream from methods decorated with param.depends
  • Adds ability from parameterized classes
  • DynamicMap allows declaring whether to dependencies on parameterized method
  • Add unit test
  • Update docs

@philippjfr
Copy link
Member Author

Tempted to leave testing and docs until there is a param release to update to but I'll defer to your judgement @jlstevens. If you agree this is ready to review/merge.

@jlstevens
Copy link
Contributor

I'm not sure whether I want to merge it yet but one thing that would make me happier is if there were a param version check so that the new execution path would only apply for current param dev versions or higher.

@@ -749,14 +755,34 @@ def __init__(self, callback, initial_items=None, **params):
'and no longer needs to be specified.')
del params['sampled']

super(DynamicMap, self).__init__(initial_items, callback=callback, **params)
invalid = [s for s in self.streams if not isinstance(s, Stream)]
# Validate streams by ensuring parameterized objects and methods are wrapped in ParamStream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a utility here? Something like:

valid, invalid = util.parameterized_streams(streams)

I'm not quite sure what you need invalid for though...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look below you'll see that invalid streams will raise errors. Happy to factor that out if you want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops missed that. I think the utility could raise the exception for invalid inputs.

@@ -1263,6 +1263,13 @@ def get_param_values(data):
return params


def is_param_method(obj):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like something that could live in param...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'll add that in a PR, I'm also duplicating it in panel, so that would definitely make sense.

parameters=parameters, **params
)
for p in self.parameters:
self.parameterized.param.watch(self._listener, p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any use of unwatch yet. Surely there are situations where clean up is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining _listener, wouldn't a lambda be sufficient?


@property
def contents(self):
if self.is_method: return {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it isn't a method, I assume the contents is based on what ParamValues used to do? I'm not sure yet, but I expected this stream to be just for triggering, i.e always return {}. That might suggest to me that we can leave ParamValues as it was an make ParamStream its own thing...

Copy link
Contributor

@jlstevens jlstevens Aug 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words maybe (decorated?) parameterized methods should have their own stream class independent of arbitrary parameterized things...


# Backward compatibility
def ParamValues(*args, **kwargs):
param.main.warning('ParamValues stream is deprecated, use ParamStream instead.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now called Params?

@jlstevens
Copy link
Contributor

Thanks for splitting it into Params and ParamMethod: I think this is semantically cleaner.

I am now happy to merge even though there are two items left on the TODO list (unit tests and docs) as we can now test this out with a dev release. Of course, we will then have to address those two items (and any new issues we encounter) later.

@jlstevens jlstevens merged commit d38f11c into master Aug 30, 2018
@philippjfr philippjfr deleted the param_watch branch November 12, 2018 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants