예제 #1
0
def test_join_option_string_types():
    a = symbol('a', 'var * {x: ?string}')
    b = symbol('b', 'var * {x: string}')
    c = symbol('c', 'var * {x: ?string}')

    assert (join(a, b, 'x').dshape == join(b, a, 'x').dshape ==
            dshape('var * {x: string}'))

    assert (join(a, c, 'x').dshape == join(c, a, 'x').dshape ==
            dshape('var * {x: ?string}'))
예제 #2
0
def test_join_on_single_column():
    a = symbol('a', 'var * {x: int, y: int, z: int}')
    b = symbol('b', 'var * {x: int, y: int, w: int}')

    expr = join(a, b.x)

    assert expr.on_right == 'x'
예제 #3
0
def test_join_suffixes():
    a = symbol('a', 'var * {x: int, y: int}')
    b = join(a, a, 'x', suffixes=('_l', '_r'))

    assert isdistinct(b.fields)
    assert len(b.fields) == 3
    assert set(b.fields) == set(['x', 'y_l', 'y_r'])
예제 #4
0
def test_join_on_same_table():
    a = symbol('a', 'var * {x: int, y: int}')

    c = join(a, a, 'x')

    assert isdistinct(c.fields)
    assert len(c.fields) == 3
예제 #5
0
def test_join_on_same_columns():
    a = symbol('a', 'var * {x: int, y: int, z: int}')
    b = symbol('b', 'var * {x: int, y: int, w: int}')

    c = join(a, b, 'x')

    assert isdistinct(c.fields)
    assert len(c.fields) == 5
    assert 'y_left' in c.fields
    assert 'y_right' in c.fields
예제 #6
0
def test_join_exceptions():
    """
    exception raised for mismatched schema;
    exception raised for no shared fields
    """
    a = symbol('a', 'var * {x: int}')
    b = symbol('b', 'var * {x: string}')
    with pytest.raises(TypeError) as excinfo:
        join(a, b, 'x')

    assert "Schemata of joining columns do not match," in str(excinfo.value)
    assert "x=int32 and x=string" in str(excinfo.value)

    b = symbol('b', 'var * {z: int}')
    with pytest.raises(ValueError) as excinfo:
        join(a, b)

    assert "No shared columns between a and b" in str(excinfo.value)

    b = symbol('b', 'var * {x: int}')
    with pytest.raises(ValueError) as excinfo:
        join(a, b, how='inner_')

    assert "Got: inner_" in str(excinfo.value)
예제 #7
0
def test_raise_error_if_join_on_no_columns():
    a = symbol('a', 'var * {x: int}')
    b = symbol('b', 'var * {y: int}')

    assert raises(ValueError, lambda: join(a, b))
예제 #8
0
def test_join_option_types():
    a = symbol('a', 'var * {x: ?int}')
    b = symbol('b', 'var * {x: int}')

    assert join(a, b, 'x').dshape == dshape('var * {x: int}')
    assert join(b, a, 'x').dshape == dshape('var * {x: int}')
예제 #9
0
def test_join_type_promotion_option():
    a = symbol('a', 'var * {x: ?int32}')
    b = symbol('b', 'var * {x: int64}')

    assert join(a, b, 'x').dshape == dshape('var * {x: int64}')
예제 #10
0
def test_join_mismatched_schema():
    a = symbol('a', 'var * {x: int}')
    b = symbol('b', 'var * {x: string}')

    with pytest.raises(TypeError):
        join(a, b, 'x')
예제 #11
0
def test_join_option_types_outer():
    a = symbol('a', 'var * {x: ?int}')
    b = symbol('b', 'var * {x: int}')

    assert (join(a, b, 'x', how='outer').dshape == join(
        b, a, 'x', how='outer').dshape == dshape('var * {x: ?int}'))