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

New pipe method for more intuitive multidimensional dim transforms #3790

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions holoviews/util/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ def register(cls, key, function):
"""
cls._custom_funcs[key] = function

@classmethod
def pipe(cls, func, *args, **kwargs):
"""
Wrapper to give multidimensional transforms a more intuitive syntax.
For a custom function 'func' with signature (*args, **kwargs), call as
dim.pipe(func, *args, **kwargs).
"""
args = list(args) # make mutable
for k, arg in enumerate(args):
if isinstance(arg, basestring):
args[k] = dim(arg)
return dim(args[0], func, *args[1:], **kwargs)

# Builtin functions
def __abs__(self): return dim(self, abs)
def __round__(self, ndigits=None):
Expand Down