def check_type_and_values_of_specification_dict(specification_dict,
                                                unique_alternatives):
    """
    Verifies that the values of specification_dict have the correct type, have
    the correct structure, and have valid values (i.e. are actually in the set
    of possible alternatives). Will raise various errors if / when appropriate.

    Parameters
    ----------
    specification_dict : OrderedDict.
        Keys are a proper subset of the columns in `long_form_df`. Values are
        either a list or a single string, `"all_diff"` or `"all_same"`. If a
        list, the elements should be:

            - single objects that are within the alternative ID column of
              `long_form_df`
            - lists of objects that are within the alternative ID column of
              `long_form_df`. For each single object in the list, a unique
              column will be created (i.e. there will be a unique coefficient
              for that variable in the corresponding utility equation of the
              corresponding alternative). For lists within the
              `specification_dict` values, a single column will be created for
              all the alternatives within iterable (i.e. there will be one
              common coefficient for the variables in the iterable).
    unique_alternatives : 1D ndarray.
        Should contain the possible alternative id's for this dataset.

    Returns
    -------
    None.
    """
    for key in specification_dict:
        specification = specification_dict[key]
        if isinstance(specification, str):
            if specification not in ["all_same", "all_diff"]:
                msg = "specification_dict[{}] not in ['all_same', 'all_diff']"
                raise ValueError(msg.format(key))

        elif isinstance(specification, list):
            # Imagine that the specification is [[1, 2], 3]
            # group would be [1, 2]
            # group_item would be 1 or 2. group_item should never be a list.
            for group in specification:
                group_is_list = isinstance(group, list)
                if group_is_list:
                    for group_item in group:
                        if isinstance(group_item, list):
                            msg = "Wrong structure for specification_dict[{}]"
                            msg_2 = " Values can be a list of lists of ints,"
                            msg_3 = " not lists of lists of lists of ints."
                            total_msg = msg.format(key) + msg_2 + msg_3
                            raise ValueError(total_msg)

                        elif group_item not in unique_alternatives:
                            msg_1 = "{} in {} in specification_dict[{}]"
                            msg_2 = " is not in long_format[alt_id_col]"
                            total_msg = (msg_1.format(group_item, group, key) +
                                         msg_2)
                            raise ValueError(total_msg)
                else:
                    if group not in unique_alternatives:
                        msg_1 = "{} in specification_dict[{}]"
                        msg_2 = " is not in long_format[alt_id_col]"
                        raise ValueError(msg_1.format(group, key) + msg_2)

        else:
            msg = "specification_dict[{}] must be 'all_same', 'all_diff', or"
            msg_2 = " a list."
            raise TypeError(msg.format(key) + msg_2)

    return None
def check_type_and_values_of_specification_dict ( specification_dict , unique_alternatives ) : for key in specification_dict : specification = specification_dict [ key ] if isinstance ( specification , str ) : if specification not in [ "all_same" , "all_diff" ] : msg = "specification_dict[{}] not in ['all_same', 'all_diff']" raise ValueError ( msg . format ( key ) ) elif isinstance ( specification , list ) : for group in specification : group_is_list = isinstance ( group , list ) if group_is_list : for group_item in group : if isinstance ( group_item , list ) : msg = "Wrong structure for specification_dict[{}]" msg_2 = " Values can be a list of lists of ints," msg_3 = " not lists of lists of lists of ints." total_msg = msg . format ( key ) + msg_2 + msg_3 raise ValueError ( total_msg ) elif group_item not in unique_alternatives : msg_1 = "{} in {} in specification_dict[{}]" msg_2 = " is not in long_format[alt_id_col]" total_msg = ( msg_1 . format ( group_item , group , key ) + msg_2 ) raise ValueError ( total_msg ) else : if group not in unique_alternatives : msg_1 = "{} in specification_dict[{}]" msg_2 = " is not in long_format[alt_id_col]" raise ValueError ( msg_1 . format ( group , key ) + msg_2 ) else : msg = "specification_dict[{}] must be 'all_same', 'all_diff', or" msg_2 = " a list." raise TypeError ( msg . format ( key ) + msg_2 ) return None
Verifies that the values of specification_dict have the correct type, have
    the correct structure, and have valid values (i.e. are actually in the set
    of possible alternatives). Will raise various errors if / when appropriate.

    Parameters
    ----------
    specification_dict : OrderedDict.
        Keys are a proper subset of the columns in `long_form_df`. Values are
        either a list or a single string, `"all_diff"` or `"all_same"`. If a
        list, the elements should be:

            - single objects that are within the alternative ID column of
              `long_form_df`
            - lists of objects that are within the alternative ID column of
              `long_form_df`. For each single object in the list, a unique
              column will be created (i.e. there will be a unique coefficient
              for that variable in the corresponding utility equation of the
              corresponding alternative). For lists within the
              `specification_dict` values, a single column will be created for
              all the alternatives within iterable (i.e. there will be one
              common coefficient for the variables in the iterable).
    unique_alternatives : 1D ndarray.
        Should contain the possible alternative id's for this dataset.

    Returns
    -------
    None.