コード例 #1
0
def test_clear_cache_all(df):
    @orca.table(cache=True)
    def table():
        return df

    @orca.column('table', cache=True)
    def z(table):
        return df.a

    @orca.injectable(cache=True)
    def x():
        return 'x'

    @orca.injectable(autocall=False, memoize=True)
    def y(s):
        return s + 'y'

    orca.eval_variable('table.z')
    orca.eval_variable('x')
    orca.get_injectable('y')('x')

    assert list(orca._TABLE_CACHE.keys()) == ['table']
    assert list(orca._COLUMN_CACHE.keys()) == [('table', 'z')]
    assert list(orca._INJECTABLE_CACHE.keys()) == ['x']
    assert orca._MEMOIZED['y'].value.cache == {(('x',), None): 'xy'}

    orca.clear_cache()

    assert orca._TABLE_CACHE == {}
    assert orca._COLUMN_CACHE == {}
    assert orca._INJECTABLE_CACHE == {}
    assert orca._MEMOIZED['y'].value.cache == {}
コード例 #2
0
def test_eval_variable(df):
    orca.add_injectable('x', 3)
    assert orca.eval_variable('x') == 3

    @orca.injectable()
    def func(x):
        return 'xyz' * x
    assert orca.eval_variable('func') == 'xyzxyzxyz'
    assert orca.eval_variable('func', x=2) == 'xyzxyz'

    @orca.table()
    def table(x):
        return df * x
    pdt.assert_series_equal(orca.eval_variable('table.a'), df.a * 3)
コード例 #3
0
def test_always_dataframewrapper(df):
    @orca.table()
    def table():
        return df / 2

    @orca.table()
    def table2(table):
        assert isinstance(table, orca.DataFrameWrapper)
        return table.to_frame() / 2

    result = orca.eval_variable('table2')
    pdt.assert_frame_equal(result.to_frame(), df / 4)