def __init__(self, data_frame, independent_var, dependent_var, independent_var_levels=None): """ :param data_frame: data frame to use for tests :param independent_var: a string type column with at least two levels :param dependent_var: a measure type column :param independent_var_levels: if independent_var has exactly two levels this parameter can be omitted, otherwise two levels in independent_var need to be supplied as a tuple """ dataframe_helper = DataFrameHelper(data_frame) # ensure data_frame is valid if not dataframe_helper.is_valid_data_frame(): raise BIException.dataframe_invalid() # ensure data_frame contains a column by name independent_var if not dataframe_helper.has_column(independent_var): raise BIException.column_does_not_exist(independent_var) # ensure column, independent_var, is of type string if not dataframe_helper.is_string_column(independent_var): raise BIException.non_string_column(independent_var) # ensure data_frame contains a column by name dependent_var if not dataframe_helper.has_column(dependent_var): raise BIException.column_does_not_exist(dependent_var) # ensure column, dependent_var, is of numeric type if not dataframe_helper.is_numeric_column(dependent_var): raise BIException.non_numeric_column(dependent_var) self._data_frame = data_frame self._independent_var = independent_var self._dependent_var = dependent_var self._independent_var_levels = self._get_independent_var_levels() if independent_var_levels != None and type(independent_var_levels) in [ list, tuple ]: if len(independent_var_levels) != 2: raise BIException( "independent_var_levels should only contain two levels") for level in independent_var_levels: if level not in self._independent_var_levels: raise BIException('Column, %s, does not have level "%s"' % (self._independent_var, level)) self._independent_var_levels = independent_var_levels else: if len(self._independent_var_levels) != 2: raise BIException( 'Column, %s, should have exactly two levels, but it has %d levels' % (self._independent_var, len(self._independent_var_levels)))
def __init__(self, data_frame, column1, column2): dataframe_helper = DataFrameHelper(data_frame) if not dataframe_helper.is_valid_data_frame(): raise BIException.dataframe_invalid() if not dataframe_helper.has_column(column1): raise BIException.column_does_not_exist(column1) if not dataframe_helper.is_numeric_column(column1): raise BIException.non_numeric_column(column1) if not dataframe_helper.has_column(column2): raise BIException.column_does_not_exist(column2) if not dataframe_helper.is_numeric_column(column2): raise BIException.non_numeric_column(column2) self._data_frame = data_frame self._column1 = column1 self._column2 = column2