datar.misc
function
datar.misc.
pipe
(
data
, func
, *args
, **kwargs
)
Apply a function to the data
This function is similar to pandas.DataFrame.pipe() and allows you to apply custom functions in a piping workflow. Works with any data type.
Parameters
data
(Any) — The data object (can be any type)func
(Callable) — Function to apply to the data.args
andkwargs
arepassed intofunc
.*args
— Positional arguments passed intofunc
**kwargs
— Keyword arguments passed intofunc
Returns (Any)
The return value of func
Examples
>>> import datar.all as dr>>> # Works with lists
>>> [1, 2, 3] >> dr.pipe(lambda x: [i * 2 for i in x])
[2, 4, 6]
>>> # Works with dicts
>>> data = {'a': 1, 'b': 2}
>>> data >> dr.pipe(lambda x: {k: v * 2 for k, v in x.items()})
{'a': 2, 'b': 4}
>>> # With additional arguments
>>> def add_value(data, value):
... return [x + value for x in data]
>>> [1, 2, 3] >> dr.pipe(add_value, 10)
[11, 12, 13]
>>> # Chain multiple operations
>>> [1, 2, 3] >> dr.pipe(lambda x: [i * 2 for i in x]) >> dr.pipe(sum)
12