build_value_map_list()

Build a list of ValueMap objects from a pandas DataFrame, optionally including validity periods.

Usage

Source

build_value_map_list(
    df,
    source_col="source",
    target_col="target",
    valid_from_col="valid_from",
    valid_to_col="valid_to"
)

Parameters

df: pd.DataFrame

DataFrame where each row represents a mapping.

source_col: str = "source"

Column name for source values.

target_col: str = "target"

Column name for target values.

valid_from_col: str = "valid_from"

Optional column name for validity start date. Defaults to “valid_from”.

valid_to_col: str = "valid_to"
Optional column name for validity end date. Defaults to “valid_to”.

Returns

list[ValueMap]
List of ValueMap objects created from the DataFrame.

Raises

ValueError

If DataFrame is empty or required columns are missing.

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

Notes

  • If validity columns exist and contain non-null values, they will be used.
  • If validity columns are absent or contain only nulls, they are ignored.

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)
>>> value_maps = build_value_map_list(df, 'source', 'target')
>>> isinstance(value_maps[0], ValueMap)
True