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
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
def test_dimensions_fails(): with pytest.raises(TypeError): _dimensions(dshape('(T, U) -> U'))
def test_tuple(): assert _dimensions('1 * (int, string)') == 2 assert _dimensions('3 * (int, string)') == 2 assert _dimensions('(int, string)') == 1
def test_option(): assert _dimensions('?int') == _dimensions('int') assert _dimensions('3 * ?int') == _dimensions('3 * int')