Ejemplo n.º 1
0
def coerce_core(result, dshape, odo_kwargs=None):
    """Coerce data to a core data type."""
    if iscoretype(result):
        return result
    elif isscalar(dshape):
        result = coerce_scalar(result, dshape, odo_kwargs=odo_kwargs)
    elif istabular(dshape) and isrecord(dshape.measure):
        result = into(DataFrame, result, **(odo_kwargs or {}))
    elif iscollection(dshape):
        dim = _dimensions(dshape)
        if dim == 1:
            result = into(Series, result, **(odo_kwargs or {}))
        elif dim > 1:
            result = into(np.ndarray, result, **(odo_kwargs or {}))
        else:
            raise ValueError("Expr with dshape dimensions < 1 should have been handled earlier: dim={}".format(str(dim)))
    else:
        raise ValueError("Expr does not evaluate to a core return type")

    return result
Ejemplo n.º 2
0
def coerce_core(result, dshape, odo_kwargs=None):
    """Coerce data to a core data type."""
    if iscoretype(result):
        return result
    elif isscalar(dshape):
        result = coerce_scalar(result, dshape, odo_kwargs=odo_kwargs)
    elif istabular(dshape) and isrecord(dshape.measure):
        result = into(DataFrame, result, **(odo_kwargs or {}))
    elif iscollection(dshape):
        dim = _dimensions(dshape)
        if dim == 1:
            result = into(Series, result, **(odo_kwargs or {}))
        elif dim > 1:
            result = into(np.ndarray, result, **(odo_kwargs or {}))
        else:
            msg = "Expr with dshape dimensions < 1 should have been handled earlier: dim={}"
            raise ValueError(msg.format(str(dim)))
    else:
        msg = "Expr does not evaluate to a core return type"
        raise ValueError(msg)

    return result
Ejemplo n.º 3
0
def test_dimensions_fails():
    with pytest.raises(TypeError):
        _dimensions(dshape('(T, U) -> U'))
Ejemplo n.º 4
0
def test_tuple():
    assert _dimensions('1 * (int, string)') == 2
    assert _dimensions('3 * (int, string)') == 2
    assert _dimensions('(int, string)') == 1
Ejemplo n.º 5
0
def test_option():
    assert _dimensions('?int') == _dimensions('int')
    assert _dimensions('3 * ?int') == _dimensions('3 * int')
Ejemplo n.º 6
0
def test_option():
    assert _dimensions('?int') == _dimensions('int')
    assert _dimensions('3 * ?int') == _dimensions('3 * int')
Ejemplo n.º 7
0
def test_dimensions_fails():
    with pytest.raises(TypeError):
        _dimensions(dshape('(T, U) -> U'))
Ejemplo n.º 8
0
def test_tuple():
    assert _dimensions('1 * (int, string)') == 2
    assert _dimensions('3 * (int, string)') == 2
    assert _dimensions('(int, string)') == 1