def test_zero(self): pdt.assert_frame_equal(self.moved_df, qtrees.clean( self.test_df, y_coord='latitude', x_coord='longitude')) move_left = [['test_1', 45.0, 45.0], ['test_2', 90, 95], ['test_3', 70, 92]] move_left_df = pd.DataFrame( move_left, columns=['SampleID', 'longitude', 'latitude']) move_left_df = move_left_df.set_index('SampleID') zero_left = [['test_1', 0.0, 0.0], ['test_2', 45, 50], ['test_3', 25, 47]] zero_left_df = pd.DataFrame( zero_left, columns=['SampleID', 'longitude', 'latitude']) zero_left_df = zero_left_df.set_index('SampleID') zero_left_df.index.name = self.index pdt.assert_frame_equal(zero_left_df, qtrees.clean(move_left_df, y_coord='latitude', x_coord='longitude'))
def test_clean_df(self): unclean_dic = { 'test_id_sw': [-180, -90], 'test_id_nw': [-180, 90], 'test_id_ne': [180, 90], 'test_id_se': [180, -90], 'test_id_np': ["Not provided", "Not provided"], 'test_id_na': ["", ""] } to_clean_dataframe = pd.DataFrame.from_dict( unclean_dic, orient='index', columns=['longitude', 'latitude']) to_clean_dataframe.index.name = self.index correct_cleaned_points = { 'test_id_sw': [0, 0], 'test_id_nw': [0, 180], 'test_id_ne': [360, 180], 'test_id_se': [360, 0] } correct_cleaned_df = pd.DataFrame.from_dict( correct_cleaned_points, orient='index', columns=['longitude', 'latitude']) correct_cleaned_df.index.name = self.index correct_cleaned_df['latitude'] = correct_cleaned_df['latitude'].astype( float) # noqa correct_cleaned_df['longitude'] = correct_cleaned_df[ 'longitude'].astype(float) # noqa cleaned = qtrees.clean(to_clean_dataframe, y_coord='latitude', x_coord='longitude') pdt.assert_frame_equal(cleaned, correct_cleaned_df) lat_long_str_pts = [['test_id_np', "Not provided", "Not provided"], ['test_id_na', "", ""]] str_only_df = pd.DataFrame( lat_long_str_pts, columns=['SampleID', 'longitude', 'latitude']) str_only_df = str_only_df.set_index(self.index) with self.assertRaises(ValueError): qtrees.clean(str_only_df, 'latitude', 'longitude')
def test_trees_correct(self): threshold = 2 self.clean = qtrees.clean(self.test_df, y_coord='latitude', x_coord='longitude') test_tree, test_samples = qtrees.get_results(self.moved_df, threshold, index='SampleID') pdt.assert_frame_equal(test_samples.sort_index(), self.correct_dataframe.sort_index()) self.assertEqual(test_tree.compare_subsets(self.correct_tree), 0.0) self.assertEqual(test_tree.compare_rfd(self.correct_tree), 0.0)