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
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)
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
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)
def test_lazy_tbl_table_string(db): tbl = LazyTbl(db, 'addresses') tbl.tbl.columns.user_id
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)
def test_sql_group_by(db, group_vars): tbl = LazyTbl(db, addresses, funcs=funcs) group_by(tbl, *group_vars)