Compute Relations API

compute_structural_relations(input_parquet, relation_ids)

Compute canonical structural relations for every unordered pair of distinct codes.

Rows follow the canonical pair orientation (shallower code first, code order on ties); the relation name describes code_j relative to code_i and is not a bidirectional label. Codes in different sector trees receive the explicit cross_sector relation. No exclusion processing happens here and nothing is written.

Parameters:

Name Type Description Default
input_parquet str

Descriptions parquet with index, level, and code columns.

required
relation_ids Mapping[str, int]

Mapping of structural relation names to IDs. Every relation name produced by the hierarchy must be mapped; cross_sector defaults to 99.

required

Returns:

Type Description
DataFrame

DataFrame with idx_i, idx_j, code_i, code_j,

DataFrame

structural_relation_id, structural_relation_name.

Raises:

Type Description
ValueError

If the hierarchy produces a relation name absent from relation_ids.