from petl import unique, look look(table1) table2 = unique(table1, 'foo') look(table2) # isordered table = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 3, True), ('b', 2)) from petl import isordered, look look(table) isordered(table, key='foo') isordered(table, key='foo', strict=True) isordered(table, key='foo', reverse=True) # rowgroupby table = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 3, True), ('b', 2)) from petl import rowgroupby, look look(table) # group entire rows for key, group in rowgroupby(table, 'foo'): print key, list(group)
def test_isordered(): table1 = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 3, True), ('b', 2)) assert isordered(table1, key='foo') assert not isordered(table1, key='foo', reverse=True) assert not isordered(table1, key='foo', strict=True) table2 = (('foo', 'bar', 'baz'), ('b', 2, True), ('a', 1, True), ('b', 3)) assert not isordered(table2, key='foo') table3 = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 2, True), ('b', 3)) assert isordered(table3, key=('foo', 'bar')) assert isordered(table3) table4 = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 3, True), ('b', 2)) assert not isordered(table4, key=('foo', 'bar')) assert not isordered(table4) table5 = (('foo', 'bar', 'baz'), ('b', 3, True), ('b', 2), ('a', 1, True)) assert not isordered(table5, key='foo') assert isordered(table5, key='foo', reverse=True) assert not isordered(table5, key='foo', reverse=True, strict=True)
def test_isordered(): table1 = (("foo", "bar", "baz"), ("a", 1, True), ("b", 3, True), ("b", 2)) assert isordered(table1, key="foo") assert not isordered(table1, key="foo", reverse=True) assert not isordered(table1, key="foo", strict=True) table2 = (("foo", "bar", "baz"), ("b", 2, True), ("a", 1, True), ("b", 3)) assert not isordered(table2, key="foo") table3 = (("foo", "bar", "baz"), ("a", 1, True), ("b", 2, True), ("b", 3)) assert isordered(table3, key=("foo", "bar")) assert isordered(table3) table4 = (("foo", "bar", "baz"), ("a", 1, True), ("b", 3, True), ("b", 2)) assert not isordered(table4, key=("foo", "bar")) assert not isordered(table4) table5 = (("foo", "bar", "baz"), ("b", 3, True), ("b", 2), ("a", 1, True)) assert not isordered(table5, key="foo") assert isordered(table5, key="foo", reverse=True) assert not isordered(table5, key="foo", reverse=True, strict=True)