import pathlib
import yaml


def read_yaml_data(data_filename: str, names=None) -> dict:
    """Read in a YAML data file as a dictionary"""
    data_path = pathlib.Path(data_filename)
    try:
        with data_path.open('r', encoding='utf-8') as fp:
            yaml_data = yaml.safe_load(fp)
    except FileNotFoundError:
        raise

    return {key: value for key, value in yaml_data.items() if key in names} if names else yaml_data