bayesline.api.equity.resolve_grouping_labels

bayesline.api.equity.resolve_grouping_labels#

bayesline.api.equity.resolve_grouping_labels(portfolio_ids: Sequence[str], groupings: Mapping[str, Mapping[str, str]]) dict[str, list[str]]#

Resolve per-fund grouping labels onto rows, coarsest level first.

For each row id (bare or path-typed parent:child:..., including :{REST} residuals):

  1. A key equal to the full row id wins outright — a per-row override. An empty-string label here explicitly leaves the row unlabeled.

  2. Otherwise a trailing {REST} segment is stripped — a residual row classifies by its parent chain — and the path is walked from the root toward the leaf. At each level, a key matches when its :-separated segments equal a tail of the path up to that level ('P4' matches P4 anywhere; 'P3:P4' only where P4 sits directly under P3).

  3. The first (coarsest) level with any matching key decides the row; among its matches the longest (most qualified) key wins.

  4. A row with no match anywhere resolves to "". On any key other than an exact row id, empty-string labels are treated as unset.

Groupings under the reserved bayesline/ namespace carry per-row values keyed by exact row id and are looked up exactly, never via the path walk.

Parameters#

portfolio_idsSequence[str]

Row ids to resolve, bare or path-typed, including any :{REST} residual rows.

groupingsMapping[str, Mapping[str, str]]

Per-grouping label maps, as PortfolioHierarchySettings.groupings.

Returns#

dict[str, list[str]]

One label column per grouping, aligned to portfolio_ids.