skrub.Expr.skb.clone#

Expr.skb.clone(drop_values=True)[source]#

Get an independent clone of the expression.

Parameters:
drop_valuesbool, default=True

Whether to drop the initial values passed to skrub.var(). This is convenient for example to serialize expressions without creating large files.

Returns:
clone

A new expression which does not share its state (such as fitted estimators) or cache with the original, and possibly without the variables’ values.

Examples

>>> import skrub
>>> c = skrub.var('a', 0) + skrub.var('b', 1)
>>> c
<BinOp: add>
Result:
―――――――
1
>>> c.skb.get_data()
{'a': 0, 'b': 1}
>>> clone = c.skb.clone()
>>> clone
<BinOp: add>
>>> clone.skb.get_data()
{}

We can ask to keep the variable values:

>>> clone = c.skb.clone(drop_values=False)
>>> clone.skb.get_data()
{'a': 0, 'b': 1}

Note that in that case the cache used for previews is still cleared. So if we want the preview we need to prime the new expression by evaluating it once (either directly or by adding more steps to it):

>>> clone
<BinOp: add>
>>> clone.skb.eval()
1
>>> clone
<BinOp: add>
Result:
―――――――
1