def expand_data_source(patches, state2data, key_name):
    """Add data to a bokeh patch object

    :param bokeh.models.renderers.GlyphRenderer patches: states as glyphs.
    :param dict state2data: keys are states abbreviation and values are data.
    :param str key_name: name to use for the key in data source.
    :return: (*bokeh.models.renderers.GlyphRenderer*) -- updated patches.
    :raises TypeError:
        if ``state2data`` is not a dict.
        if ``key_name`` is not a str.
    :raises ValueError:
        if states in ``state2data`` and  ``patches`` differ.
    """
    if not isinstance(state2data, dict):
        raise TypeError("state2data must be a dict")
    if not isinstance(key_name, str):
        raise TypeError("key_name must be a str")

    if len(set(patches.data_source.data["state_name"]) - set(state2data.keys())) != 0:
        raise ValueError("states in patches are missing from state2data")

    patches.data_source.data[key_name] = [
        state2data[s] for s in patches.data_source.data["state_name"]
    ]
    return patches