def test_cast_int_to_float(self): result = render(P(type=_join_type_map.index('inner'), colnames=(['A'], [])), pd.DataFrame({'A': [1, 2, 3]}), PR('', {'A': [1.0, 2.0, 4.0]})) expected = pd.DataFrame({'A': [1.0, 2.0]}) assert_frame_equal(result.dataframe, expected)
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_type_mismatch(self): result = render(P(type=_join_type_map.index('inner'), colnames=(['A'], [])), pd.DataFrame({'A': [1, 2, 3]}), PR('', {'A': ['1', '2', '3']})) self.assertEqual(result, ProcessResult(error=( 'Types do not match for key column "A" (number and text). ' 'Please use a type conversion module ' 'to make these column types consistent.' )))
def test_importcols(self): result = render(P(type=_join_type_map.index('inner'), colnames=(['key'], []), select_columns=True, importcols=(['col2'], [])), pd.DataFrame({'col1': ['a', 'a'], 'key': ['b', 'c']}), PR('', { 'key': ['b', 'd'], 'col2': ['c', 'a'], 'col3': ['d', 'b'], })) self.assertEqual(['col1', 'key', 'col2'], list(result.dataframe.columns))
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_join(self): # Nothing too technical, do not need to test pandas functions result = render(P(type=_join_type_map.index('inner'), colnames=(['key'], [])), pd.DataFrame({'col1': ['a', 'a'], 'key': ['b', 'c']}), PR('', { 'key': ['b', 'd'], 'col2': ['c', 'a'], 'col3': ['d', 'b'], })) assert_frame_equal(result.dataframe, pd.DataFrame({ 'col1': ['a'], 'key': ['b'], 'col2': ['c'], 'col3': ['d'], }))