import csv


def _load_key_value_csv(csv_path, key_type=str, value_type=str, ignore_header=False):
    """
    Loads a CSV file that contains key, value pairs as rows into a dictionary.

    :param csv_path: Path to the CSV file.
    :type csv_path: str
    :param key_type: Type of the keys (first column), to cast them when creating the dictionary. Optional, default: str
    :type key_type: type
    :param value_type: Type of the values (second column), to cast them when creating the dictionary. Optional,
        default: str
    :type value_type: type
    :para, ignore_header: Set to true to ignore the first row of the CSV file, which is assumed to be a header
        with metadata (usually the name of the columns). Optional, default: False
    :raises ValueError: If the type conversion is not possible.
    :raises OSError: If there is a problem reading the file.
    :return: A dictionary that maps each element of the first column in the CSV to its corresponding pair in the
        second column for the same row. The type of the keys and of the values is defined by the corresponding
        parameters.
    :rtype: dict
    """
    with open(csv_path, newline='') as csv_file:
        reader = csv.reader(csv_file)
        if ignore_header:
            # Skip first row.
            next(reader)
        csv_dict = {key_type(row[0]): value_type(row[1]) for row in reader}

    return csv_dict