build_single_component_map()

Build a ComponentMap from a DataFrame, mapping one source to one target.

Usage

Source

build_single_component_map(
    df,
    source_component,
    target_component,
    agency="FAKE_AGENCY",
    id=None,
    name=None,
    source_cl=None,
    target_cl=None,
    version="1.0",
    description=None,
    source_col="source",
    target_col="target",
    valid_from_col="valid_from",
    valid_to_col="valid_to",
    generate_urn=True,
    default_value=None
)

Parameters

df: pd.DataFrame

DataFrame where each row represents a mapping.

source_component: str

ID of the source component.

target_component: str

ID of the target component.

agency: str = "FAKE_AGENCY"

Agency maintaining the representation map. Defaults to “FAKE_AGENCY”.

id: str | None = None

Identifier for the representation map.

name: str | None = None

Name of the representation map.

source_cl: str | None = None

URN or identifier for the source codelist or data type.

target_cl: str | None = None

URN or identifier for the target codelist or data type.

version: str = "1.0"

Version of the representation map. Defaults to “1.0”.

description: str | None = None

Optional description of the representation map.

source_col: str = "source"

Column name for source values. Defaults to “source”.

target_col: str = "target"

Column name for target values. Defaults to “target”.

valid_from_col: str = "valid_from"

Column name for validity start date. Defaults to “valid_from”.

valid_to_col: str = "valid_to"

Column name for validity end date. Defaults to “valid_to”.

generate_urn: bool = True

If True, generate URN for the RepresentationMap. Defaults to True.

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

Returns

ComponentMap
A ComponentMap object mapping the source to the target component.

Raises

ValueError

If DataFrame is empty or required columns are missing.

TypeError
If source or target columns contain non-string values.

Examples

    >>> import pandas as pd
    >>> data = {
    ...     'source': ['BE', 'FR'],
    ...     'target': ['BEL', 'FRA'],
    ...     'valid_from': ['2020-01-01', None],
    ...     'valid_to': ['2025-12-31', None]
    ... }
    >>> df = pd.DataFrame(data)
    >>> cm = build_single_component_map(
    ...     df,
    ...     source_component="COUNTRY",
    ...     target_component="COUNTRY",
    ...     agency="ECB",
    ...     id="CM1",
    ...     name="Country Component Map",
    ...     source_cl="urn:source:codelist",
    ...     target_cl="urn:target:codelist"
    ... )
    >>> isinstance(cm, ComponentMap)
True