One column’s lineage record.
ColumnNode(
name,
dtype,
roles,
source,
parent_cols,
dtype_history,
sparse=False,
removed_by=None
)
A node is mutable: an in-place step (e.g. StepNormalize) updates dtype and appends to dtype_history without creating a new node, and a step that drops a column sets removed_by and the node is archived rather than discarded, so ancestry still resolves through it. Live nodes are read with lineage["name"]; archived ones through Lineage.removed.
Attributes
name: str
-
Current column name.
dtype: nw.dtypes.DType
-
Current narwhals dtype (may change across steps).
roles: set[str]
-
Current role names, as a set (unordered).
source: str
-
Which step produced this column: "original" for an input column, otherwise the producing step’s id. An in-place transform does not change source: it does not produce a column.
parent_cols: list[str]
-
The input column name(s) this column descends from. Empty for original columns and for parent-less produced columns (e.g. those added by StepIntercept).
dtype_history: list[nw.dtypes.DType]
-
The dtype trajectory: the creation dtype followed by an entry for each step that changed the dtype (not one per step boundary).
sparse: bool
-
Whether this column is currently sparse.
removed_by: str | None
-
None while the column is live; set to the dropping step’s id once it has been removed from the data frame and archived.
Examples
Nodes are read off a fitted recipe’s Lineage by column name. Here a numeric column is normalized in place, and StepDummy then expands a categorical column:
recipe = (
Recipe(target="Status")
.add(StepNormalize(s.numeric_features()))
.add(StepDummy(s.nominal_features()))
)
fitted = recipe.fit(credit)
lineage = fitted.lineage
node = lineage["Home_rent"]
node.name, node.source, node.parent_cols
('Home_rent', 'dummy', ['Home'])
Age was normalized in place, so it is still an "original" column but its dtype history records the integer to float cast:
lineage["Age"].source, lineage["Age"].dtype_history
('original', [Int64, Float64])
Home was consumed by the dummy step, so it is archived with removed_by set:
[(n.name, n.removed_by) for n in lineage.removed if n.name == "Home"]