skrub.Expr.skb.set_name#

Expr.skb.set_name(name)[source]#

Give a name to this expression.

Returns a modified copy The name is displayed in the graph and reports so this can be useful to mark relevant parts of the pipeline.

Moreover, the evaluation of this step can be bypassed and the result provided directly by providing a value for this name to eval(), transform(), predict() etc. (see examples)

Parameters:
namestr

The name for this step. Must be unique within a pipeline. Cannot start with "_skrub_".

Returns:
A new expression with the given name.

Examples

>>> import skrub
>>> a = skrub.var('a', 1)
>>> b = skrub.var('b', 2)
>>> c = (a + b).skb.set_name('c')
>>> c
<c | BinOp: add>
Result:
―――――――
3
>>> c.skb.name
'c'
>>> d = c * 10
>>> d
<BinOp: mul>
Result:
―――――――
30
>>> d.skb.eval()
30
>>> d.skb.eval({'a': 10, 'b': 5})
150

We can override the result of c. When we do, the operands a and b are not evaluated: evaluating c just returns the value we passed.

>>> d.skb.eval({'c': -1}) # -1 * 10
-10

For expressions that are not variables, the name can be set back to the default None:

>>> e = c.skb.set_name(None)
>>> e.skb.name
>>> c.skb.name
'c'