本文整理汇总了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'))