skrub.DataOp.skb.id#

DataOp.skb.id#

A unique ID for this DataOp.

The ID is generated when the DataOp is defined and preserved when serializing, copying or cloning the DataOp. It can be used to look up a specific node with DataOp.skb.find() or override its computation by using the ID as a key in the environment passed, for example, to DataOp.skb.eval() or SkrubLearner.predict().

Usually, giving a node an explicit name with DataOp.skb.set_name() if preferred than relying on the ID, but the ID can be useful if you do not control the definition of the DataOp or if you have an already-fitted SkrubLearner and want to override a node which was not given a name.

See also

DataOp.skb.set_name

Set a name for the DataOp. In most cases using a name is preferred to relying on the ID.

Notes

The IDs of nodes can be inspected with DataOp.skb.id, by passing show_ids=True to DataOp.skb.draw_graph(), or in the nodes’ detailed pages generated by DataOp.skb.full_report().

Examples

>>> import skrub
>>> a = skrub.var("a")
>>> b = skrub.var("b")
>>> c = skrub.var("c")
>>> d = a + b
>>> d
<BinOp: add>
>>> d.skb.id
244252108859391526605448044030022310698
>>> e = d * c
>>> e.skb.find(d.skb.id)
<BinOp: add>
>>> env = {"a": 1, "b": 2, "c": 5}
>>> e.skb.eval(env)  # (1 + 2) * 5
15

Override the computation of d, injecting 100 as its value:

>>> e.skb.eval(env | {d.skb.id: 100})  # 100 * 5
500

Note: the preferred way to refer to a node is to rely on an explicit name rather than the ID:

>>> d = (a + b).skb.set_name("d")
>>> d.skb.name
'd'
>>> e = d * c
>>> e.skb.find("d")
<d | BinOp: add>
>>> e.skb.eval(env | {"d": 100})  # 100 * 5
500