skrub.Expr.skb.apply_func#
- Expr.skb.apply_func(func, *args, **kwargs)[source]#
Apply the given function.
This is a convenience function;
X.skb.apply_func(func)
is equivalent toskrub.deferred(func)(X)
.- Parameters:
- funcfunction
The function to apply to the expression.
- args
additional positional arguments passed to
func
.- kwargs
named arguments passed to
func
.
- Returns:
- expression
The expression that evaluates to the result of calling
func
asfunc(self, *args, **kwargs)
.
Examples
>>> import skrub
>>> def count_words(text, sep=None): ... return len(text.split(sep))
>>> text = skrub.var("text", "Hello, world!") >>> text <Var 'text'> Result: ――――――― 'Hello, world!'
>>> count = text.skb.apply_func(count_words) >>> count <Call 'count_words'> Result: ――――――― 2 >>> count.skb.eval({"text": "one two three four"}) 4
We can pass extra arguments:
>>> text.skb.apply_func(count_words, sep="\n") <Call 'count_words'> Result: ――――――― 1
Using
.skb.apply_func
is the same as usingdeferred
, for example:>>> skrub.deferred(count_words)(text) <Call 'count_words'> Result: ――――――― 2