def test_join(self): # Nothing too technical, do not need to test pandas functions set_string(self.url_pval, self.valid_workflow_URL) set_string(self.colnames_pval, 'key') set_integer(self.type_pval, _join_type_map.index("inner")) result = JoinURL.render(self.wfm, self.table) assert_frame_equal(self.ref_left_join, result.dataframe)
def test_type_mismatch(self): # Joining on column with different dtypes should fail set_string(self.url_pval, self.valid_workflow_URL) set_string(self.colnames_pval, 'key') set_integer(self.type_pval, _join_type_map.index("inner")) result = JoinURL.render(self.wfm, self.table_with_types) self.assertEqual(("Types do not match for key column 'key' (number and text). " \ 'Please use a type conversion module to make these column types consistent.'), result.error)
def test_type_num_cast(self): # Joining on column that is both int and float, module should convert to float version = self.wfm.store_fetched_table(self.ext_workflow_with_types) self.wfm.set_fetched_data_version(version) set_string(self.url_pval, self.valid_workflow_URL) set_string(self.colnames_pval, 'key') set_integer(self.type_pval, _join_type_map.index("inner")) result = JoinURL.render(self.wfm, self.table_with_types) assert_frame_equal(self.ref_left_join_with_types, result.dataframe)
def test_concat_with_source(self): version = self.wfm.store_fetched_table(self.ext_workflow) self.wfm.set_fetched_data_version(version) set_string(self.url_pval, self.valid_workflow_URL) set_checkbox(self.source_columns_pval, True) set_integer(self.type_pval, _type_map.index("include columns from both workflows")) result = ConcatURL.render(self.wfm, self.table) # Sanitize dataframe to clean index created by pandas concat() result.sanitize_in_place() ref = self.ref_outer_concat.copy() ref.insert(0, _source_column_name, ['Current', 'Current', '2', '2']) assert_frame_equal(ref, result.dataframe)
def test_importcols(self): # Should only import 1 column set_string(self.url_pval, self.valid_workflow_URL) set_string(self.colnames_pval, 'key') set_string(self.importcols_pval, 'col2') set_checkbox(self.select_columns_pval, True) set_integer(self.type_pval, _join_type_map.index("inner")) result = JoinURL.render(self.wfm, self.table.copy()) assert_frame_equal(self.ref_left_join[['col1', 'key', 'col2']], result.dataframe) # When select_column false, should import all columns set_checkbox(self.select_columns_pval, False) result = JoinURL.render(self.wfm, self.table.copy()) assert_frame_equal(self.ref_left_join, result.dataframe)
def test_concat(self): version = self.wfm.store_fetched_table(self.ext_workflow) self.wfm.set_fetched_data_version(version) set_string(self.url_pval, self.valid_workflow_URL) set_checkbox(self.source_columns_pval, False) set_integer(self.type_pval, _type_map.index("only include this workflow's columns")) result = ConcatURL.render(self.wfm, self.table) # Sanitize dataframe to clean index created by pandas concat() result.sanitize_in_place() assert_frame_equal(self.ref_source_only_concat, result.dataframe) set_integer(self.type_pval, _type_map.index("only include matching columns")) result = ConcatURL.render(self.wfm, self.table) # Sanitize dataframe to clean index created by pandas concat() result.sanitize_in_place() assert_frame_equal(self.ref_inner_concat, result.dataframe) set_integer(self.type_pval, _type_map.index("include columns from both workflows")) result = ConcatURL.render(self.wfm, self.table) # Sanitize dataframe to clean index created by pandas concat() result.sanitize_in_place() assert_frame_equal(self.ref_outer_concat, result.dataframe)