예제 #1
0
def test_datashape_from_query():

    x = sdb.zeros(4)
    q = sdb.afl.apply(x, 'g', 'f0 + 3').query
    ds = SciDBDataShape.from_query(sdb, q)

    assert ds.chunk_size == x.datashape.chunk_size
    assert ds.chunk_overlap == x.datashape.chunk_overlap
    assert ds.dim_names == x.dim_names
    assert set(ds.sdbtype.names) == set(x.sdbtype.names + ['g'])
예제 #2
0
def test_datashape_from_query():

    x = sdb.zeros(4)
    q = sdb.afl.apply(x, 'g', 'f0 + 3').query
    ds = SciDBDataShape.from_query(sdb, q)

    assert ds.chunk_size == x.datashape.chunk_size
    assert ds.chunk_overlap == x.datashape.chunk_overlap
    assert ds.dim_names == x.dim_names
    assert set(ds.sdbtype.names) == set(x.sdbtype.names + ['g'])
예제 #3
0
def change_axis_schema(datashape,
                       axis,
                       start=None,
                       stop=None,
                       chunk=None,
                       overlap=None,
                       name=None):
    """
    Create a new DataShape by modifying the parameters of one axis

    Parameters
    ----------
    datashape : SciDBDataShape
        The template data shape
    axis : int
        Which axis to modify
    stop : int (optional)
        New axis upper bound
    chunk : int (optional)
        New chunk size
    overlap : int (optional)
        New chunk overlap
    name : str (optional)
        New dimension name

    Returns
    -------
    new_schema : SciDBDataShape
       The new schema, obtained by overriding the input parameters
       of the template datashape along the specified axis
    """
    from .scidbarray import SciDBDataShape

    names = list(datashape.dim_names)
    starts = list(datashape.dim_low)
    stops = list(datashape.dim_high)
    chunks = list(datashape.chunk_size)
    overlaps = list(datashape.chunk_overlap)
    if stop is not None:
        stops[axis] = stop
    if chunk is not None:
        chunks[axis] = chunk
    if overlap is not None:
        overlaps[axis] = overlap
    if name is not None:
        names[axis] = name
    if start is not None:
        starts[axis] = start
    return SciDBDataShape(None,
                          datashape.sdbtype,
                          dim_names=names,
                          chunk_size=chunks,
                          chunk_overlap=overlaps,
                          dim_low=starts,
                          dim_high=stops)
예제 #4
0
def _rename_dim(datashape, index, name):
    from scidbpy import SciDBDataShape

    names = datashape.dim_names
    if names[index] == name:
        return datashape

    schema = "tmp" + datashape.schema
    # XXX doesn't work if fixing non-first duplicate dim name
    schema = schema.replace('%s=' % names[index], '%s=' % name, 1)
    return SciDBDataShape.from_schema(schema)
예제 #5
0
def _rename_dim(datashape, index, name):
    from scidbpy import SciDBDataShape

    names = datashape.dim_names
    if names[index] == name:
        return datashape

    schema = "tmp" + datashape.schema
    # XXX doesn't work if fixing non-first duplicate dim name
    schema = schema.replace('%s=' % names[index], '%s=' % name, 1)
    return SciDBDataShape.from_schema(schema)
예제 #6
0
def _rename_att(datashape, index, name):
    from scidbpy import SciDBDataShape, sdbtype

    atts = datashape.sdbtype.names
    if atts[index] == name:
        return datashape

    rep = [list(x) for x in datashape.sdbtype.full_rep]
    rep[index][0] = name
    rep = [tuple(x) for x in rep]

    schema = "tmp%s%s" % (sdbtype(np.dtype(rep)).schema, datashape.dim_schema)
    return SciDBDataShape.from_schema(schema)
예제 #7
0
def _rename_att(datashape, index, name):
    from scidbpy import SciDBDataShape, sdbtype

    atts = datashape.sdbtype.names
    if atts[index] == name:
        return datashape

    rep = [list(x) for x in datashape.sdbtype.full_rep]
    rep[index][0] = name
    rep = [tuple(x) for x in rep]

    schema = "tmp%s%s" % (sdbtype(np.dtype(rep)).schema, datashape.dim_schema)
    return SciDBDataShape.from_schema(schema)
예제 #8
0
def _rename_att(datashape, index, name):
    from scidbpy import SciDBDataShape, sdbtype

    atts = datashape.sdbtype.names
    if atts[index] == name:
        return datashape

    rep = [list(x) for x in datashape.sdbtype.full_rep]
    rep[index][0] = name
    rep = [tuple(x) for x in rep]

    # py2 numpy doesn't like unicode here
    rep = [(str(r[0]), r[1]) for r in rep]

    schema = "tmp%s%s" % (sdbtype(np.dtype(rep)).schema, datashape.dim_schema)
    return SciDBDataShape.from_schema(schema)
예제 #9
0
def _rename_att(datashape, index, name):
    from scidbpy import SciDBDataShape, sdbtype

    atts = datashape.sdbtype.names
    if atts[index] == name:
        return datashape

    rep = [list(x) for x in datashape.sdbtype.full_rep]
    rep[index][0] = name
    rep = [tuple(x) for x in rep]

    # py2 numpy doesn't like unicode here
    rep = [(str(r[0]), r[1]) for r in rep]

    schema = "tmp%s%s" % (sdbtype(np.dtype(rep)).schema, datashape.dim_schema)
    return SciDBDataShape.from_schema(schema)