def assign_discrete_colors(data, gg, aes_name, color_col, labels):
    """
    Logic to assign colors in the discrete case.

    We're going to check and see if the user has defined their own color
    palette. If they have then we'll use those colors for mapping. If not,
    then we'll generate some default colors. We also have to be careful here
    because for some odd reason the next() function is different in Python 2.7
    and Python 3.0. Once we've done that we generate the legends based off
    the (color -> value) mapping.

    Parameters
    ----------
    data : DataFrame
        dataframe which should have colors assigned to
    gg : ggplot object, which holds information and gets a legend assigned
    color_col : The column we are using to color.
    aes_name : string
        Which aesthetic needs a color mapping; 'color' | 'fill'

    Returns
    -------
    data : DataFrame
        the changed dataframe
    legend_entry : dict
        An entry into the legend dict
        Documented in `components.legend`
    """
    _mcolumn = aes_name % ':::%s_mapping:::'
    possible_colors = np.unique(data[color_col])
    if gg.manual_color_list:
        color = color_gen(len(possible_colors), gg.manual_color_list)
    else:
        color = color_gen(len(possible_colors))
    color_mapping = dict((value, six.next(color)) for value in possible_colors)
    data[_mcolumn] = data[color_col].apply(lambda x: color_mapping[x])

    legend_entry = {'column_name': color_col,
                    'dict': dict((v, k) for k, v in color_mapping.items()),
                    'scale_type': 'discrete'}
    return data, legend_entry
dataset/ETHPy150Open yhat/ggplot/ggplot/components/colors.py/assign_discrete_colors/swapped operands of `%`