Example #1
0
 def test1(self):
     df = df_iris.copy()
     out_df = sort(df,
                   input_cols=['species', 'petal_length'],
                   is_asc=['desc', 'asc'])['out_table']
     print(df)
     print(out_df)
Example #2
0
 def test_validation(self):
     df = get_iris()
     with self.assertRaises(BrighticsFunctionException) as bfe:
         out_df = sort(df, input_cols=[], is_asc=['desc'])['out_table']
         
     test_errors = bfe.exception.errors
     self.assertTrue({'0033': ['input_cols']} in test_errors)
Example #3
0
 def test_default(self):
     df = load_iris()
     out_df = sort(df,
                   input_cols=['species', 'petal_length'],
                   is_asc=['desc', 'asc'])['out_table']
     print(df)
     print(out_df)
Example #4
0
    def test_example_sort(self):
        in_table = self.example_table
        expected_table = pd.DataFrame({'A': [3, 2, 1], 'B': ['c', 'b', 'a']})

        sort_out = sort(table=in_table, input_cols=['B'],
                        is_asc=False)['out_table'].reset_index(drop=True)
        print(sort_out)
        pd.testing.assert_frame_equal(expected_table, sort_out)
Example #5
0
    def test_second(self):

        st = sort(self.testdata,
                  input_cols=['petal_length', 'species'],
                  is_asc=False)
        DF2 = st['out_table'].values
        # print(DF2)
        np.testing.assert_array_equal(DF2[0][0:4], [7.7, 2.6, 6.9, 2.3])
        np.testing.assert_array_equal(DF2[1][0:4], [7.7, 3.8, 6.7, 2.2])
        np.testing.assert_array_equal(DF2[2][0:4], [7.7, 2.8, 6.7, 2.0])
        np.testing.assert_array_equal(DF2[3][0:4], [7.6, 3.0, 6.6, 2.1])
        np.testing.assert_array_equal(DF2[4][0:4], [7.9, 3.8, 6.4, 2.0])
Example #6
0
    def test_first(self):

        st = sort(self.testdata,
                  input_cols=['sepal_length', 'sepal_width'],
                  is_asc=True)
        DF1 = st['out_table'].values
        # print(DF1)
        np.testing.assert_array_equal(DF1[0][0:4], [4.3, 3.0, 1.1, 0.1])
        np.testing.assert_array_equal(DF1[1][0:4], [4.4, 2.9, 1.4, 0.2])
        np.testing.assert_array_equal(DF1[2][0:4], [4.4, 3.0, 1.3, 0.2])
        np.testing.assert_array_equal(DF1[3][0:4], [4.4, 3.2, 1.3, 0.2])
        np.testing.assert_array_equal(DF1[4][0:4], [4.5, 2.3, 1.3, 0.3])
Example #7
0
 def test2(self):
     df = get_iris()
     out_df = sort(df, input_cols=[], is_asc=['desc'])['out_table']
     print(df)
     print(out_df)