def merge_annotations(interaction_dataframe, columns):
    """Merges the annotations for a protein-protein interaction.

    Given two columns of a protein-protein interaction dataframe, each of
    which contains a type of annotation data, this function returns the merged
    set of those annotations.

    E.g. Column 1: {IPR011333, IPR003131, IPR000210}
         Column 2: {GO:0046872}
         Result: {GO:0046872, IPR011333, IPR003131, IPR000210}

    Parameters
    ----------
    interaction_dataframe : DataFrame
        DataFrame containing protein-protein interactions and annotations.
    columns : list
        A list of annotation columns to merge. Expects the column contents to
        be array-like, not strings.

    Returns
    -------
    pandas Series of sets
        Array containing a set of annotations for each interaction (row).
    """

    # replace NaNs with empty sets
    for i in columns:
        interaction_dataframe.loc[interaction_dataframe[
            i].isnull(), i] = interaction_dataframe.loc[interaction_dataframe[
                i].isnull(), i].apply(lambda x: set())

    # join all sets in each supplied column
    # the unpacking operator can accept an array of lists or sets
    merged_annotations = interaction_dataframe[columns].apply(
        lambda x: set().union(*x), axis=1)
    """ Example usage
    Row entry:
        interpro_xref_A               {IPR029199, IPR026667}
        interpro_xref_B    {IPR027417, IPR001889, IPR013672}
        Name: 1, dtype: object
    Lambda result:
        {'IPR001889', 'IPR013672', 'IPR026667', 'IPR027417', 'IPR029199'}
    """

    return merged_annotations