def test_resolve_hidden_alias(): define_alias("jets", "pt", lambda j: j.pt / 1000.0) df = DataFrame() df1 = df.jets.pt assert df1.filter is None assert df1.child_expr is not None assert '1000' in ast.dump(df1.child_expr)
def test_resolve_in_filter(): define_alias("jets", "pt", lambda j: j.pt / 2000.0) df = DataFrame() df1 = df.jets.pt[df.jets.pt > 50.0] assert df1.filter is not None assert isinstance(df1.filter, Column) check_for_compare(df1.filter.child_expr, '2000')
def test_resolve_hidden_name(): define_alias("jets", "pt", lambda j: j.pt / 1000.0) df = DataFrame() df = df.jets r = lookup_alias(df, "pt") assert r is not None df1 = r.apply(df) assert df1.child_expr is not None t = ast.dump(df1.child_expr) assert '1000' in t
def test_resolve_two_names_good_2(): define_alias("jets", "pts", lambda j: j.pt / 1000.0) define_alias("eles", "pts", lambda j: j.pt / 2000.0) df = DataFrame() df = df.eles r = lookup_alias(df, "pts") assert r is not None df1 = r.apply(df) assert df1.child_expr is not None t = ast.dump(df1.child_expr) assert '2000' in t
def test_resolve_dependent(): define_alias("jets", "pts", lambda j: j.pt / 1000.0) define_alias("jets", "pt", lambda j: j.pt / 2000.0) df = DataFrame() df1 = df.jets.pts assert df1.filter is None assert df1.child_expr is not None assert '1000' in ast.dump(df1.child_expr) assert isinstance(df1.child_expr, ast.BinOp) assert df1.child_expr.left is not None assert isinstance(df1.child_expr.left, ast_DataFrame) df2 = cast(ast_DataFrame, df1.child_expr.left) assert df2.dataframe.child_expr is not None assert '2000' in ast.dump(df2.dataframe.child_expr)
def test_resolve_in_filter_twice(): define_alias("jets", "pt", lambda j: j.pt / 2000.0) df = DataFrame() df1 = df.jets.pt[(df.jets.pt > 50.0) & (df.jets.pt < 60.0)] assert df1.filter is not None assert isinstance(df1.filter.child_expr, ast.BoolOp) bool_op = df1.filter.child_expr assert len(bool_op.values) == 2 op_1 = bool_op.values[0] # type: ast.AST op_2 = bool_op.values[1] # type: ast.AST assert isinstance(op_1, ast_Column) assert isinstance(op_2, ast_Column) check_for_compare(op_1.column.child_expr, '2000') check_for_compare(op_1.column.child_expr, '2000')
def test_resolve_partial_wildcard_nogood_1(): define_alias("jets", "pts", lambda j: j.pt / 1000.0) df = DataFrame() df = df.eles r = lookup_alias(df, "pts") assert r is None
def test_define_alias_no_error(): define_alias(".jets", "pts", lambda j: j.pt / 1000.0)
def test_resolve_wilecard_nogood(): define_alias("", "pts", lambda j: j.pt / 1000.0) df = DataFrame() r = lookup_alias(df, "pt") assert r is None
def test_resolve_wilecard_good_1(): define_alias("", "pts", lambda j: j.pt / 1000.0) df = DataFrame() df = df.jets r = lookup_alias(df, "pts") assert r is not None
def test_resolve_well_specified_nogood_3(): define_alias(".jets", "pts", lambda j: j.pt / 1000.0) df = DataFrame() df = df.eles r = lookup_alias(df, "pts") assert r is None
def test_resolve_root_good(): define_alias(".", "pts", lambda j: j.pt / 1000.0) df = DataFrame() df = df r = lookup_alias(df, "pts") assert r is not None
def test_define_alias_no_name_no_err(): define_alias("", "pts", lambda j: j.pt / 1000.0)