def _map_column_name(key_store, target_name):
    """Figure out the internal column name for a given target name

    If a column is used as the index of a table, its PyTables name is 'index'
    instead of the desired name. Handle that gracefully.
    """
    try:
        index_name = key_store.attrs.info['index']['index_name']
    except KeyError:
        index_name = ''

    if index_name == target_name:
        return 'index'
    else:
        return target_name