Exemplo n.º 1
0
lkp['orange'][19:140]
lkp['apple'][1]
lkp['apple'][2]
lkp['apple'][4]
lkp['apple'][5]
lkp['orange'][5]

table = (('type', 'start', 'stop', 'value'),
         ('apple', 1, 4, 'foo'),
         ('apple', 3, 7, 'bar'),
         ('orange', 4, 9, 'baz'))

from petl import look
from petlx.interval import facetintervallookupone
look(table)
lkp = facetintervallookupone(table, key='type', startfield='start', stopfield='stop', valuespec='value')
lkp['apple'][1:2]
lkp['apple'][2:4]
lkp['apple'][2:5]
lkp['apple'][4:5]
lkp['orange'][4:5]
lkp['apple'][5:7]
lkp['orange'][5:7]
lkp['apple'][8:9]
lkp['orange'][8:9]
lkp['orange'][9:14]
lkp['orange'][19:140]
lkp['apple'][1]
lkp['apple'][2]
lkp['apple'][4]
lkp['apple'][5]
Exemplo n.º 2
0
def test_facetintervallookupone():
    
    table = (('type', 'start', 'stop', 'value'),
             ('apple', 1, 4, 'foo'),
             ('apple', 3, 7, 'bar'),
             ('orange', 4, 9, 'baz'))
    
    lkp = facetintervallookupone(table, facet='type', start='start', stop='stop', value='value')
    
    actual = lkp['apple'].find(1, 2)
    expect = 'foo'
    assertequal(expect, actual)
    
    try:
        actual = lkp['apple'].find(2, 4)
    except DuplicateKeyError:
        pass
    else:
        assert False, 'expected error'
    
    try:
        actual = lkp['apple'].find(2, 5)
    except DuplicateKeyError:
        pass
    else:
        assert False, 'expected error'
    
    actual = lkp['apple'].find(4, 5)
    expect = 'bar'
    assertequal(expect, actual)
    
    actual = lkp['orange'].find(4, 5)
    expect = 'baz'
    assertequal(expect, actual)
    
    actual = lkp['apple'].find(5, 7)
    expect = 'bar'
    assertequal(expect, actual)

    actual = lkp['orange'].find(5, 7)
    expect = 'baz'
    assertequal(expect, actual)
    
    actual = lkp['apple'].find(8, 9)
    expect = None
    assertequal(expect, actual)
    
    actual = lkp['orange'].find(8, 9)
    expect = 'baz'
    assertequal(expect, actual)
    
    actual = lkp['orange'].find(9, 14)
    expect = None
    assertequal(expect, actual)
    
    actual = lkp['orange'].find(19, 140)
    expect = None
    assertequal(expect, actual)
    
    actual = lkp['apple'].find(1)
    expect = None
    assertequal(expect, actual)
    
    actual = lkp['apple'].find(2)
    expect =  'foo'
    assertequal(expect, actual)
    
    actual = lkp['apple'].find(4)
    expect = 'bar'
    assertequal(expect, actual)
    
    actual = lkp['apple'].find(5)
    expect = 'bar'
    assertequal(expect, actual)
    
    actual = lkp['orange'].find(5)
    expect = 'baz'
    assertequal(expect, actual)
    
    actual = lkp['apple'].find(8)
    expect = None
    assertequal(expect, actual)
    
    actual = lkp['orange'].find(8)
    expect = 'baz'
    assertequal(expect, actual)