Exemple #1
0
    def test_init(self):
        b = Between('a', 'b')
        eq_(b.f, 'a')
        eq_(b.t, 'b')
        eq_(b.f_open, False)
        eq_(b.t_open, False)

        b = Between('a', 'b', True, False)
        eq_(b.f, 'a')
        eq_(b.t, 'b')
        eq_(b.f_open, True)
        eq_(b.t_open, False)

        b = Between('a', 'b', False, True)
        eq_(b.f, 'a')
        eq_(b.t, 'b')
        eq_(b.f_open, False)
        eq_(b.t_open, True)

        b = Between(None, 'b')
        eq_(b.f, None)
        eq_(b.t, 'b')
        eq_(b.f_open, False)
        eq_(b.t_open, False)

        b = Between('a', None)
        eq_(b.f, 'a')
        eq_(b.t, None)
        eq_(b.f_open, False)
        eq_(b.t_open, False)

        eq_(GT('a').__dict__, Between('a', None, True, False).__dict__)
        eq_(GE('a').__dict__, Between('a', None, False, False).__dict__)
        eq_(LT('b').__dict__, Between(None, 'b', False, True).__dict__)
        eq_(LE('b').__dict__, Between(None, 'b', False, False).__dict__)
Exemple #2
0
 def test_inner_id2lr(self):
     result = bmerge(self.df1, self.df2, ['id1', Between('s', 'e', True, True), 'id2'], ['id3', 'v', 'id4'])
     print(result)
     for idx, row in result.iterrows():
         assert_true(row['id1'] == row['id3'])
         assert_true(row['id2'] == row['id4'])
         assert_true(row['s'] < row['v'] and row['e'] > row['v'], f'row: {row}')
Exemple #3
0
 def test_null_id1l_opposite(self):
     result = bmerge(self.df5, self.df1, ['id3', 'v'], ['id1', Between('s', 'e', True, True)], how='inner')
     print(result)
     for idx, row in result.iterrows():
         if not pandas.isnull(row['id3']):
             assert_true(row['id1'] == row['id3'])
             assert_true(row['s'] <= row['v'], f'row: {row}')
             assert_true(row['e'] >= row['v'], f'row: {row}')
Exemple #4
0
 def test_right_id2lr(self):
     result = bmerge(self.df1, self.df2, ['id1', Between('s', 'e', True, True), 'id2'], ['id3', 'v', 'id4'], 'right')
     print(result)
     for idx, row in result.iterrows():
         if pandas.isnull(row['id1']):
             assert_false(any([row_['id1'] == row['id3'] and
                               row_['id2'] == row['id4'] and
                               row_['s'] < row['v'] < row_['e']
                               for idx, row_ in self.df1.iterrows()]))
         else:
             assert_true(row['id1'] == row['id3'], f'row: {row}')
             assert_true(row['id2'] == row['id4'], f'row: {row}')
             assert_true(row['s'] < row['v'] and row['e'] > row['v'], f'row: {row}')
Exemple #5
0
    def test_build(self):
        df = pandas.DataFrame({'a': [1,2,3], 'b': [5,6,7]})
        b = Between('a', 'b')
        r = b(df)[1]
        eq_(r.range_from, 2)
        eq_(r.range_to, 6)
        eq_(r.from_opened, False)
        eq_(r.to_opened, False)

        b = Between('a', 'b', True, False)
        r = b(df)[1]
        eq_(r.range_from, 2)
        eq_(r.range_to, 6)
        eq_(r.from_opened, True)
        eq_(r.to_opened, False)

        b = Between('a', 'b', False, True)
        r = b(df)[1]
        eq_(r.range_from, 2)
        eq_(r.range_to, 6)
        eq_(r.from_opened, False)
        eq_(r.to_opened, True)

        b = Between(None, 'b')
        r = b(df)[1]
        eq_(r.range_from, None)
        eq_(r.range_to, 6)
        eq_(r.from_opened, False)
        eq_(r.to_opened, False)

        b = Between('a', None)
        r = b(df)[1]
        eq_(r.range_from, 2)
        eq_(r.range_to, None)
        eq_(r.from_opened, False)
        eq_(r.to_opened, False)
Exemple #6
0
 def test_inner_simple(self):
     result = bmerge(self.df1, self.df2, [Between('s', 'e', True, True)], ['v'])
     print(result)
     for idx, row in result.iterrows():
         assert_true(row['s'] < row['v'] and row['e'] > row['v'], f'row: {row}')
Exemple #7
0
 def test_inner_fail_key4(self):
     result = bmerge(self.df1, self.df2, Between('s', 'e', True, True), Between('id1', 'id2', True, True))
Exemple #8
0
 def test_inner_fail_key3(self):
     result = bmerge(self.df1, self.df2, Between('a', 'e', True, True), 'v')
Exemple #9
0
 def test_inner_fail_validation2(self):
     result = bmerge(self.df1, self.df2, Between('s', 'e', True, True), 'v', how='abc')
Exemple #10
0
 def test_inner_fail_validation1(self):
     result = bmerge(self.df1, self.df2, Between('s', 'e', True, True), ['id1', 'v'])
Exemple #11
0
 def test_inner_name2(self):
     result = bmerge(self.df1, self.df3, ['id1', Between('s', 'e', True, True)], ['id1', 'v'])
     print(result)
     for idx, row in result.iterrows():
         assert_true(row['id1_x'] == row['id1_y'])
         assert_true(row['s'] < row['v'] and row['e'] > row['v'], f'row: {row}')
Exemple #12
0
 def test_column_check3(self):
     df = pandas.DataFrame({'a': [1, 2, 3], 'b': [5, 6, 7]})
     b = Between('a', 'b')
     assert_true(b.column_check(df.columns))
Exemple #13
0
 def test_build_fail2(self):
     df = pandas.DataFrame({'a': [1, 2, 3], 'b': [5, 6, 7]})
     b = Between('a', 'c')
     r = b(df)[1]
Exemple #14
0
 def test_init_fail(self):
     b = Between(None, None)