当前位置: 首页>>代码示例>>Python>>正文


Python Table.inner_join方法代码示例

本文整理汇总了Python中journalism.Table.inner_join方法的典型用法代码示例。如果您正苦于以下问题:Python Table.inner_join方法的具体用法?Python Table.inner_join怎么用?Python Table.inner_join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在journalism.Table的用法示例。


在下文中一共展示了Table.inner_join方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestTableJoin

# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import inner_join [as 别名]
class TestTableJoin(unittest.TestCase):
    def setUp(self):
        self.left_rows = (
            (1, 4, 'a'),
            (2, 3, 'b'),
            (None, 2, 'c')
        )

        self.right_rows = (
            (1, 4, 'a'),
            (2, 3, 'b'),
            (None, 2, 'c')
        )

        self.number_type = NumberType()
        self.text_type = TextType()
        self.column_types = (self.number_type, self.number_type, self.text_type)

        self.left = Table(self.left_rows, self.column_types, ('one', 'two', 'three'))
        self.right = Table(self.right_rows, self.column_types, ('four', 'five', 'six'))

    def test_inner_join(self):
        new_table = self.left.inner_join('one', self.right, 'four')

        self.assertEqual(len(new_table.rows), 3)
        self.assertEqual(len(new_table.columns), 6)

        self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a', 1, 4, 'a'))
        self.assertSequenceEqual(new_table.rows[1], (2, 3, 'b', 2, 3, 'b'))
        self.assertSequenceEqual(new_table.rows[2], (None, 2, 'c', None, 2, 'c'))

    def test_inner_join2(self):
        new_table = self.left.inner_join('one', self.right, 'five')

        self.assertEqual(len(new_table.rows), 1)
        self.assertEqual(len(new_table.columns), 6)

        self.assertSequenceEqual(new_table.rows[0], (2, 3, 'b', None, 2, 'c'))

    def test_inner_join_func(self):
        new_table = self.left.inner_join(
            lambda left: '%i%s' % (left['two'], left['three']),
            self.right,
            lambda right: '%i%s' % (right['five'], right['six'])
        )

        self.assertEqual(len(new_table.rows), 3)
        self.assertEqual(len(new_table.columns), 6)

    def test_left_outer_join(self):
        new_table = self.left.left_outer_join('one', self.right, 'four')

        self.assertEqual(len(new_table.rows), 3)
        self.assertEqual(len(new_table.columns), 6)

        self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a', 1, 4, 'a'))
        self.assertSequenceEqual(new_table.rows[1], (2, 3, 'b', 2, 3, 'b'))
        self.assertSequenceEqual(new_table.rows[2], (None, 2, 'c', None, 2, 'c'))

    def test_left_outer_join2(self):
        new_table = self.left.left_outer_join('one', self.right, 'five')

        self.assertEqual(len(new_table.rows), 3)
        self.assertEqual(len(new_table.columns), 6)

        self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a', None, None, None))
        self.assertSequenceEqual(new_table.rows[1], (2, 3, 'b', None, 2, 'c'))
        self.assertSequenceEqual(new_table.rows[2], (None, 2, 'c', None, None, None))

    def test_left_outer_func(self):
        new_table = self.left.left_outer_join(
            lambda left: '%i%s' % (left['two'], left['three']),
            self.right,
            lambda right: '%i%s' % (right['five'], right['six'])
        )

        self.assertEqual(len(new_table.rows), 3)
        self.assertEqual(len(new_table.columns), 6)

        self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a', 1, 4, 'a'))
        self.assertSequenceEqual(new_table.rows[1], (2, 3, 'b', 2, 3, 'b'))
        self.assertSequenceEqual(new_table.rows[2], (None, 2, 'c', None, 2, 'c'))
开发者ID:mickaobrien,项目名称:journalism,代码行数:84,代码来源:test_table.py


注:本文中的journalism.Table.inner_join方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。