Ejemplo n.º 1
0
def test_sql_mutate(db):
    tbl = LazyTbl(db, addresses, funcs=funcs)
    f = mutate(user_id2=_.user_id + 1)
    out1 = tbl >> f >> collect()
    out2 = tbl >> collect() >> f

    assert_frame_equal(out1, out2)
Ejemplo n.º 2
0
def test_lazy_tbl_manual_columns(db):
    tbl = LazyTbl(db, 'addresses', columns=('user_id', 'wrong_name'))
    tbl.tbl.columns.wrong_name
    tbl.tbl.columns.user_id

    with pytest.raises(AttributeError):
        tbl.tbl.columns.email_address
Ejemplo n.º 3
0
def test_lazy_tbl_shape_call_error(db):
    tbl = LazyTbl(db, 'addresses')

    call = strip_symbolic(_.id.asdkfjsdf())
    with pytest.raises(SqlFunctionLookupError) as err:
        tbl.shape_call(call)

        # suppresses context for shorter stack trace
        assert err.__suppress_context__ == True
Ejemplo n.º 4
0
def copy_to_sql(df, name, engine):
    if isinstance(engine, str):
        engine = create_engine(engine)

    df.to_sql(name,
              engine,
              dtype=auto_types(df),
              index=False,
              if_exists="replace")
    return LazyTbl(engine, name)
Ejemplo n.º 5
0
def test_lazy_tbl_table_string(db):
    tbl = LazyTbl(db, 'addresses')
    tbl.tbl.columns.user_id
Ejemplo n.º 6
0
def tets_sql_group_by_fail(db, group_var, error):
    tbl = LazyTbl(db, addresses, funcs=funcs)
    with pytest.raises(error):
        group_by(tbl, group_var)
Ejemplo n.º 7
0
def test_sql_group_by(db, group_vars):
    tbl = LazyTbl(db, addresses, funcs=funcs)
    group_by(tbl, *group_vars)