-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Disable deep hashing if memoization is off #2007
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
11c5a02
Disable deep hashing if memoization is off
philippjfr 1c89b87
Minor optimization for pandas hashing
philippjfr 839b80c
Streams can define a hashkey property
philippjfr 8b09a93
Add StreamData stream
philippjfr 3388c85
Fixed hashing of Callable keyword args
philippjfr 56d1234
Declared StreamData.data parameter constant
philippjfr 9bc7efe
Renamed Callable._memoize to Callable._stream_memoization
philippjfr 0757d8c
Added test for custom Stream.hashkey
philippjfr b63a384
Ensure hash_items are sorted
philippjfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
server-side or in Javascript in the Jupyter notebook (client-side). | ||
""" | ||
|
||
import uuid | ||
|
||
import param | ||
import numpy as np | ||
from numbers import Number | ||
|
@@ -296,6 +298,15 @@ def contents(self): | |
return {self._rename.get(k,k):v for (k,v) in filtered.items() | ||
if (self._rename.get(k,True) is not None)} | ||
|
||
@property | ||
def hashkey(self): | ||
""" | ||
The object the memoization hash is computed from. By default | ||
returns the stream contents but can be overridden to provide | ||
a custom hash key. | ||
""" | ||
return self.contents | ||
|
||
|
||
def _set_stream_parameters(self, **kwargs): | ||
""" | ||
|
@@ -352,6 +363,34 @@ def transform(self): | |
return {'counter': self.counter + 1} | ||
|
||
|
||
class StreamData(Stream): | ||
""" | ||
A Stream used to pipe arbitrary data to a callback. | ||
Unlike other streams memoization can be disabled for a | ||
StreamData stream (and is disabled by default). | ||
""" | ||
|
||
data = param.Parameter(default=None, constant=True, doc=""" | ||
Arbitrary data being streamed to a DynamicMap callback.""") | ||
|
||
def __init__(self, memoize=False, **params): | ||
super(StreamData, self).__init__(**params) | ||
self._memoize = memoize | ||
|
||
def send(self, data): | ||
""" | ||
A convenience method to send an event with data without | ||
supplying a keyword. | ||
""" | ||
self.event(data=data) | ||
|
||
@property | ||
def hashkey(self): | ||
if self._memoize: | ||
return self.contents | ||
return {'hash': uuid.uuid4().hex} | ||
|
||
|
||
class LinkedStream(Stream): | ||
""" | ||
A LinkedStream indicates is automatically linked to plot interactions | ||
|
@@ -404,11 +443,11 @@ class PointerXY(LinkedStream): | |
the plot bounds, the position values are set to None. | ||
""" | ||
|
||
x = param.ClassSelector(class_=(Number, util.basestring), default=None, | ||
x = param.ClassSelector(class_=(Number, util.basestring, tuple), default=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated change that snuck in. Allows the Pointer stream to work with nested categorical axes so worth keeping (and I can't be bothered to make a new PR). |
||
constant=True, doc=""" | ||
Pointer position along the x-axis in data coordinates""") | ||
|
||
y = param.ClassSelector(class_=(Number, util.basestring), default=None, | ||
y = param.ClassSelector(class_=(Number, util.basestring, tuple), default=None, | ||
constant=True, doc=""" | ||
Pointer position along the y-axis in data coordinates""") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fair bit faster, although still not great, hence also adding a hashkey.