def test_example_data_ops_extend():
    data_algebra.yaml.fix_ordered_dict_yaml_rep()
    ops = []
    q = 4
    x = 2
    var_name = "y"
    with data_algebra.env.Env(locals()) as env:
        ops = ops + [
            TableDescription("d", ["x", "y"]).extend(
                {"z": '_.x + _[var_name]/q + _get("x") + x'})
        ]

        ops = ops + [
            TableDescription("d", ["x", "y"]).extend(
                od(z="1/q + _.x/_[var_name]", f=1, g='"2"', h=True))
        ]

        ops = ops + [
            TableDescription("d", ["q", "y"]).extend({"z": "1/q + y"})
        ]

        ops = ops + [
            TableDescription("d", ["q", "y"]).extend(
                {"z": 'q/_get("q") + y + _.q'})
        ]

    for o in ops:
        data_algebra.yaml.check_op_round_trip(o)
def test_example_data_ops_extend():
    data_algebra.yaml.fix_ordered_dict_yaml_rep()
    ops = []
    q = 4
    x = 2
    var_name = 'y'
    with data_algebra.env.Env(locals()) as env:
        ops = ops + [
            TableDescription('d', ['x', 'y']).extend(
                {'z': '_.x + _[var_name]/q + _get("x") + x'})
        ]

        ops = ops + [
            TableDescription('d', ['x', 'y']).extend({'z': '1/q + x'})
        ]

        ops = ops + [
            TableDescription('d', ['x', 'y']).extend(
                od(z='1/q + _.x/_[var_name]', f=1, g='"2"', h=True))
        ]

        ops = ops + [
            data_algebra.pipe.build_pipeline(
                TableDescription('d', ['x', 'y']),
                Extend(od(z='1/_.y + 1/q', x='x+1')))
        ]

        ops = ops + [
            TableDescription('d', ['q', 'y']).extend({'z': '1/q + y'})
        ]

        ops = ops + [
            TableDescription('d', ['q', 'y']).extend(
                {'z': 'q/_get("q") + y + _.q'})
        ]

    for o in ops:
        data_algebra.yaml.check_op_round_trip(o)
Beispiel #3
0
def test_drop_columns():
    data_algebra.yaml.fix_ordered_dict_yaml_rep()
    db_model = data_algebra.PostgreSQL.PostgreSQLModel()

    d = pandas.DataFrame({'x': [1], 'y': [2]})

    ops = describe_pandas_table(d, "d") .\
        drop_columns(['x'])

    sql = ops.to_sql(db_model)

    res = ops.eval_pandas(od(d=d))

    data_algebra.yaml.check_op_round_trip(ops)

    expect = pandas.DataFrame({'y': [2]})

    assert data_algebra.util.equivalent_frames(expect, res)
Beispiel #4
0
def test_od():
    res = od(y=1, x='b')
    expect = collections.OrderedDict()
    expect['y'] = 1
    expect['x'] = 'b'
    assert res == expect
Beispiel #5
0
def test_od():
    res = od(y=1, x="b")
    expect = collections.OrderedDict()
    expect["y"] = 1
    expect["x"] = "b"
    assert res == expect