本文整理汇总了Python中journalism.Table.order_by方法的典型用法代码示例。如果您正苦于以下问题:Python Table.order_by方法的具体用法?Python Table.order_by怎么用?Python Table.order_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类journalism.Table
的用法示例。
在下文中一共展示了Table.order_by方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_order_by_preserves_rows
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import order_by [as 别名]
def test_order_by_preserves_rows(self):
table = Table(self.rows, self.column_types, self.column_names)
table2 = table.order_by(lambda r: r['one'])
table3 = table2.order_by(lambda r: r['one'])
self.assertIsNot(table._data[0], table2._data[0])
self.assertIs(table2._data[0], table3._data[0])
示例2: test_order_by_nulls
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import order_by [as 别名]
def test_order_by_nulls(self):
rows = (
(1, 2, None),
(2, None, None),
(1, 1, 'c'),
(1, None, 'a')
)
table = Table(rows, self.column_types, self.column_names)
new_table = table.order_by('two')
self.assertSequenceEqual(new_table.columns['two'], (1, 2, None, None))
new_table = table.order_by('three')
self.assertSequenceEqual(new_table.columns['three'], ('a', 'c', None, None))
示例3: test_order_by_reverse
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import order_by [as 别名]
def test_order_by_reverse(self):
table = Table(self.rows, self.column_types, self.column_names)
new_table = table.order_by(lambda r: r['two'], reverse=True)
self.assertEqual(len(new_table.rows), 3)
self.assertSequenceEqual(new_table.rows[0], (1, 4, 'a'))
self.assertSequenceEqual(new_table.rows[1], (2, 3, 'b'))
self.assertSequenceEqual(new_table.rows[2], (None, 2, 'c'))
示例4: test_order_by
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import order_by [as 别名]
def test_order_by(self):
table = Table(self.rows, self.column_types, self.column_names)
new_table = table.order_by('two')
self.assertIsNot(new_table, table)
self.assertEqual(len(new_table.rows), 3)
self.assertSequenceEqual(new_table.rows[0], (None, 2, 'c'))
self.assertSequenceEqual(new_table.rows[1], (2, 3, 'b'))
self.assertSequenceEqual(new_table.rows[2], (1, 4, 'a'))
# Verify old table not changed
self.assertSequenceEqual(table.rows[0], (1, 4, 'a'))
self.assertSequenceEqual(table.rows[1], (2, 3, 'b'))
self.assertSequenceEqual(table.rows[2], (None, 2, 'c'))
示例5: test_order_by_func
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import order_by [as 别名]
def test_order_by_func(self):
rows = (
(1, 2, 'a'),
(2, 1, 'b'),
(1, 1, 'c')
)
table = Table(rows, self.column_types, self.column_names)
new_table = table.order_by(lambda r: (r['one'], r['two']))
self.assertIsNot(new_table, table)
self.assertEqual(len(new_table.rows), 3)
self.assertSequenceEqual(new_table.rows[0], (1, 1, 'c'))
self.assertSequenceEqual(new_table.rows[1], (1, 2, 'a'))
self.assertSequenceEqual(new_table.rows[2], (2, 1, 'b'))