build_multi_representation_map()

Build a MultiRepresentationMap object from a pandas DataFrame.

Usage

Source

build_multi_representation_map(
    df,
    agency="FAKE_AGENCY",
    id=None,
    name=None,
    source_cls=None,
    target_cls=None,
    version="1.0",
    description=None,
    source_cols=None,
    target_cols=None,
    valid_from_col="valid_from",
    valid_to_col="valid_to",
    generate_urn=True,
    default_value=None
)

Wraps the creation of individual MultiValueMap objects and bundles them into a MultiRepresentationMap container.

Parameters

df: pd.DataFrame

DataFrame where each row represents a multi-mapping.

agency: str = "FAKE_AGENCY"

Agency maintaining the map. Defaults to “FAKE_AGENCY”.

id: str | None = None

Identifier for the map.

name: str | None = None

Name of the map.

source_cls: list[str] | None = None

URNs/IDs for source codelists/types, one per source column. When omitted, each source is represented as DataType.STRING.

target_cls: list[str] | None = None

URNs/IDs for target codelists/types, one per target column. When omitted, each target is represented as DataType.STRING.

version: str = "1.0"

Version of the map. Defaults to “1.0”.

description: str | None = None

Description of the map.

source_cols: list[str] | None = None

Source columns. Defaults to [“source”].

target_cols: list[str] | None = None

Target columns. Defaults to [“target”].

valid_from_col: str = "valid_from"

Validity start column. Defaults to “valid_from”.

valid_to_col: str = "valid_to"

Validity end column. Defaults to “valid_to”.

generate_urn: bool = True

If True and id is provided, generate a URN for the MultiRepresentationMap. Defaults to True.

default_value: str | None = None
Optional catch-all target value. When provided, source-value tuples not listed in the DataFrame resolve to this value instead of remaining unmapped. Defaults to None (no catch-all).

Returns

MultiRepresentationMap
The constructed MultiRepresentationMap object.

Raises

ValueError

If DataFrame is empty, columns are missing, or the length of source_cls/target_cls does not match the number of source/target columns.

TypeError
If non-string data is found in source/target columns.