Exemple #1
0
 def join(res1, res2):
     conn = joins.pop(0)
     tb1 = res1[0]
     col_order_1 = res1[1]
     tb2 = res2[0]
     col_order_2 = res2[1]
     if conn == ' UNETELO CN ':
         return man.unite_tables(tb1, tb2, col_order_1, col_order_2, False)
     elif conn == ' UNETELO TODO CN ':
         return man.unite_tables(tb1, tb2, col_order_1, col_order_2, True)
     elif conn == ' COMUN CN ':
         return man.intersect_tables(tb1, tb2, col_order_1, col_order_2)
     elif conn == ' SACALE ':
         return man.left_outer_intersect(tb1, tb2, col_order_1, col_order_2)
     else:
         raise ValueError('Do not recognize connective')
Exemple #2
0
 def test_unite_tables_with_repeat(self):
     expected = [('a', 1, 0.1), ('b', 2, 0.2), ('c', 3, 0.3), ('d', 4, 0.4),
                 ('e', 5, 0.5), ('a', 1, 0.1), ('b', 2, 0.2), ('c', 3, 0.3),
                 ('i', 9, 0.9), ('j', 10, 1.0)]
     test = man.unite_tables(self.tb51, self.tb52, self.tb51_order,
                             self.tb52_order, True)
     test_tb = test[0]
     # Check column entries, row order may be different, but change is
     # uniform across all columns
     str_col = test_tb['str']
     int_col = test_tb['int']
     float_col = test_tb['float']
     i = str_col.index('a')
     j = str_col.index('b')
     k = str_col.index('c')
     l = str_col.index('d')
     m = str_col.index('e')
     n = str_col.index('i')
     o = str_col.index('j')
     # Same row as a
     self.assertEqual(int_col[i], 1)
     self.assertEqual(float_col[i], 0.1)
     # Same row as b
     self.assertEqual(int_col[j], 2)
     self.assertEqual(float_col[j], 0.2)
     # Same row as c
     self.assertEqual(int_col[k], 3)
     self.assertEqual(float_col[k], 0.3)
     # Same row as d
     self.assertEqual(int_col[l], 4)
     self.assertEqual(float_col[l], 0.4)
     # Same row as e
     self.assertEqual(int_col[m], 5)
     self.assertEqual(float_col[m], 0.5)
     # Same row as n
     self.assertEqual(int_col[n], 9)
     self.assertEqual(float_col[n], 0.9)
     # Same row as o
     self.assertEqual(int_col[o], 10)
     self.assertEqual(float_col[o], 1.0)
     # Count that there are repeats
     counter_str = col.Counter(str_col)
     self.assertEqual(counter_str['a'], 2)
     self.assertEqual(counter_str['b'], 2)
     self.assertEqual(counter_str['c'], 2)
     counter_int = col.Counter(int_col)
     self.assertEqual(counter_int[1], 2)
     self.assertEqual(counter_int[2], 2)
     self.assertEqual(counter_int[3], 2)
     counter_float = col.Counter(float_col)
     self.assertEqual(counter_float[0.1], 2)
     self.assertEqual(counter_float[0.2], 2)
     self.assertEqual(counter_float[0.3], 2)
 def test_unite_tables_with_repeat(self):
     expected = [('a', 1, 0.1), ('b', 2, 0.2), ('c', 3, 0.3), ('d', 4, 0.4),
                 ('e', 5, 0.5), ('a', 1, 0.1), ('b', 2, 0.2), ('c', 3, 0.3),
                 ('i', 9, 0.9), ('j', 10, 1.0)]
     test = man.unite_tables(self.tb51, self.tb52,
                             self.tb51_order, self.tb52_order, True)
     test_tb = test[0]
     # Check column entries, row order may be different, but change is
     # uniform across all columns
     str_col = test_tb['str']
     int_col = test_tb['int']
     float_col = test_tb['float']
     i = str_col.index('a')
     j = str_col.index('b')
     k = str_col.index('c')
     l = str_col.index('d')
     m = str_col.index('e')
     n = str_col.index('i')
     o = str_col.index('j')
     # Same row as a
     self.assertEqual(int_col[i], 1)
     self.assertEqual(float_col[i], 0.1)
     # Same row as b
     self.assertEqual(int_col[j], 2)
     self.assertEqual(float_col[j], 0.2)
     # Same row as c
     self.assertEqual(int_col[k], 3)
     self.assertEqual(float_col[k], 0.3)
     # Same row as d
     self.assertEqual(int_col[l], 4)
     self.assertEqual(float_col[l], 0.4)
     # Same row as e
     self.assertEqual(int_col[m], 5)
     self.assertEqual(float_col[m], 0.5)
     # Same row as n
     self.assertEqual(int_col[n], 9)
     self.assertEqual(float_col[n], 0.9)
     # Same row as o
     self.assertEqual(int_col[o], 10)
     self.assertEqual(float_col[o], 1.0)
     # Count that there are repeats
     counter_str = col.Counter(str_col)
     self.assertEqual(counter_str['a'], 2)
     self.assertEqual(counter_str['b'], 2)
     self.assertEqual(counter_str['c'], 2)
     counter_int = col.Counter(int_col)
     self.assertEqual(counter_int[1], 2)
     self.assertEqual(counter_int[2], 2)
     self.assertEqual(counter_int[3], 2)
     counter_float = col.Counter(float_col)
     self.assertEqual(counter_float[0.1], 2)
     self.assertEqual(counter_float[0.2], 2)
     self.assertEqual(counter_float[0.3], 2)