bayesline.api.equity.hierarchy_from_df#
- bayesline.api.equity.hierarchy_from_df(df: DataFrame) tuple[Hierarchy, dict[str, str]]#
Convert a hierarchy DataFrame back to a (Hierarchy, labels) pair.
Inverse of
hierarchy_to_df(). The input must have columnslevel,code,label,parent_code. Roots are rows whereparent_codeis null. A node with no children in the table is a leaf; when every child of a node is a leaf, that node’s value is a list of leaf codes (matching the canonicalHierarchy = list[str] | Mapping[str, Hierarchy]shape).Parameters#
- dfpl.DataFrame
Hierarchy in the long
(level, code, label, parent_code)shape.
Returns#
- tuple[Hierarchy, dict[str, str]]
The reconstructed hierarchy and a code → label mapping.