コード例 #1
0
ファイル: table.py プロジェクト: garfee/blaze
    def __init__(self,
                 obj,
                 dshape=None,
                 metadata=None,
                 layout=None,
                 params=None):

        # Datashape
        # ---------

        if isinstance(dshape, basestring):
            dshape = _dshape(dshape)

        if not dshape:
            # The user just passed in a raw data source, try
            # and infer how it should be layed out or fail
            # back on dynamic types.
            self._datashape = dshape = CTableSource.infer_datashape(obj)
        else:
            # The user overlayed their custom dshape on this
            # data, check if it makes sense
            CTableSource.check_datashape(obj, given_dshape=dshape)
            self._datashape = dshape

        # Source
        # ------

        if isinstance(obj, ByteProvider):
            self.data = obj
        else:
            self.data = CTableSource(obj, dshape=dshape, params=params)

        # children graph nodes
        self.children = []

        self.space = Space(self.data)

        # Layout
        # ------

        if layout:
            self._layout = layout
        elif not layout:
            self._layout = self.data.default_layout()

        # Metadata
        # --------

        self._metadata = NDTable._metaheader + (metadata or [])

        # Parameters
        # ----------
        self.params = params
コード例 #2
0
ファイル: table.py プロジェクト: atbrox/blaze
    def __init__(self, obj, dshape=None, metadata=None, layout=None,
            params=None):

        # Datashape
        # ---------

        if isinstance(dshape, basestring):
            dshape = _dshape(dshape)

        if not dshape:
            # The user just passed in a raw data source, try
            # and infer how it should be layed out or fail
            # back on dynamic types.
            self._datashape = dshape = CTableSource.infer_datashape(obj)
        else:
            # The user overlayed their custom dshape on this
            # data, check if it makes sense
            CTableSource.check_datashape(obj, given_dshape=dshape)
            self._datashape = dshape

        # Source
        # ------

        if isinstance(obj, ByteProvider):
            self.data = obj
        else:
            self.data = CTableSource(obj, dshape=dshape, params=params)

        # children graph nodes
        self.children = []

        self.space = Space(self.data)

        # Layout
        # ------

        if layout:
            self._layout = layout
        elif not layout:
            self._layout = self.data.default_layout()

        # Metadata
        # --------

        self._metadata  = NDTable._metaheader + (metadata or [])

        # Parameters
        # ----------
        self.params = params
コード例 #3
0
ファイル: toplevel.py プロジェクト: garfee/blaze
def open(uri=None, mode='a'):
    """Open a Blaze object via an `uri` (Uniform Resource Identifier).

    Parameters
    ----------
    uri : str
        Specifies the URI for the Blaze object.  It can be a regular file too.

    mode : the open mode (string)
        Specifies the mode in which the object is opened.  The supported
        values are:

          * 'r' for read-only
          * 'w' for emptying the previous underlying data
          * 'a' for allowing read/write on top of existing data

    Returns
    -------
    out : an Array or Table object.

    """
    ARRAY = 1
    TABLE = 2

    if uri is None:
        source = CArraySource()
    else:
        uri = urlparse(uri)

        if uri.scheme == 'carray':
            path = os.path.join(uri.netloc, uri.path[1:])
            parms = params(storage=path)
            source = CArraySource(params=parms)
            structure = ARRAY

        if uri.scheme == 'ctable':
            path = os.path.join(uri.netloc, uri.path[1:])
            parms = params(storage=path)
            source = CTableSource(params=parms)
            structure = TABLE

        elif uri.scheme == 'sqlite':
            path = os.path.join(uri.netloc, uri.path[1:])
            parms = params(storage=path or None)
            source = SqliteSource(params=parms)
            structure = TABLE

        else:
            # Default is to treat the URI as a regular path
            parms = params(storage=uri.path)
            source = CArraySource(params=parms)
            structure = ARRAY

    # Don't want a deferred array (yet)
    # return NDArray(source)
    if structure == ARRAY:
        return Array(source)
    elif structure == TABLE:
        return NDTable(source)
コード例 #4
0
ファイル: table.py プロジェクト: garfee/blaze
class NDTable(Indexable, ArrayNode):
    """
    The base NDTable. Indexable contains the indexing logic for
    how to access elements, while ArrayNode contains the graph
    related logic for building expression trees with this table
    as an element.
    """

    eclass = DELAYED
    _metaheader = [
        md.deferred,
        md.tablelike,
    ]

    #------------------------------------------------------------------------
    # Properties
    #------------------------------------------------------------------------

    def __init__(self,
                 obj,
                 dshape=None,
                 metadata=None,
                 layout=None,
                 params=None):

        # Datashape
        # ---------

        if isinstance(dshape, basestring):
            dshape = _dshape(dshape)

        if not dshape:
            # The user just passed in a raw data source, try
            # and infer how it should be layed out or fail
            # back on dynamic types.
            self._datashape = dshape = CTableSource.infer_datashape(obj)
        else:
            # The user overlayed their custom dshape on this
            # data, check if it makes sense
            CTableSource.check_datashape(obj, given_dshape=dshape)
            self._datashape = dshape

        # Source
        # ------

        if isinstance(obj, ByteProvider):
            self.data = obj
        else:
            self.data = CTableSource(obj, dshape=dshape, params=params)

        # children graph nodes
        self.children = []

        self.space = Space(self.data)

        # Layout
        # ------

        if layout:
            self._layout = layout
        elif not layout:
            self._layout = self.data.default_layout()

        # Metadata
        # --------

        self._metadata = NDTable._metaheader + (metadata or [])

        # Parameters
        # ----------
        self.params = params

    @property
    def datashape(self):
        """
        Type deconstructor
        """
        return self._datashape

    @property
    def size(self):
        """
        Size of the NDTable.
        """
        # TODO: need to generalize, not every Array will look
        # like Numpy
        return sum(i.val for i in self._datashape.parameters[:-1])

    @property
    def backends(self):
        """
        The storage backends that make up the space behind the Array.
        """
        return iter(self.space)

    def __repr__(self):
        return generic_repr('NDTable', self, deferred=True)
コード例 #5
0
ファイル: table.py プロジェクト: atbrox/blaze
class NDTable(Indexable, ArrayNode):
    """
    The base NDTable. Indexable contains the indexing logic for
    how to access elements, while ArrayNode contains the graph
    related logic for building expression trees with this table
    as an element.
    """

    eclass = DELAYED
    _metaheader = [
        md.deferred,
        md.tablelike,
    ]

    #------------------------------------------------------------------------
    # Properties
    #------------------------------------------------------------------------

    def __init__(self, obj, dshape=None, metadata=None, layout=None,
            params=None):

        # Datashape
        # ---------

        if isinstance(dshape, basestring):
            dshape = _dshape(dshape)

        if not dshape:
            # The user just passed in a raw data source, try
            # and infer how it should be layed out or fail
            # back on dynamic types.
            self._datashape = dshape = CTableSource.infer_datashape(obj)
        else:
            # The user overlayed their custom dshape on this
            # data, check if it makes sense
            CTableSource.check_datashape(obj, given_dshape=dshape)
            self._datashape = dshape

        # Source
        # ------

        if isinstance(obj, ByteProvider):
            self.data = obj
        else:
            self.data = CTableSource(obj, dshape=dshape, params=params)

        # children graph nodes
        self.children = []

        self.space = Space(self.data)

        # Layout
        # ------

        if layout:
            self._layout = layout
        elif not layout:
            self._layout = self.data.default_layout()

        # Metadata
        # --------

        self._metadata  = NDTable._metaheader + (metadata or [])

        # Parameters
        # ----------
        self.params = params

    @property
    def datashape(self):
        """
        Type deconstructor
        """
        return self._datashape

    @property
    def size(self):
        """
        Size of the NDTable.
        """
        # TODO: need to generalize, not every Array will look
        # like Numpy
        return sum(i.val for i in self._datashape.parameters[:-1])

    @property
    def backends(self):
        """
        The storage backends that make up the space behind the Array.
        """
        return iter(self.space)

    def __repr__(self):
        return generic_repr('NDTable', self, deferred=True)
コード例 #6
0
def open(uri, mode='a',  eclass=_eclass.manifest):
    """Open a Blaze object via an `uri` (Uniform Resource Identifier).

    Parameters
    ----------
    uri : str
        Specifies the URI for the Blaze object.  It can be a regular file too.
        The URL scheme indicates the storage type:

          * carray: Chunked array
          * ctable: Chunked table
          * sqlite: SQLite table (the URI 'sqlite://' creates in-memory table)

        If no URI scheme is given, carray is assumed.

    mode : the open mode (string)
        Specifies the mode in which the object is opened.  The supported
        values are:

          * 'r' for read-only
          * 'w' for emptying the previous underlying data
          * 'a' for allowing read/write on top of existing data

    Returns
    -------
    out : an Array or Table object.

    """
    ARRAY = 1
    TABLE = 2

    uri = urlparse(uri)
    path = uri.netloc + uri.path
    parms = params(storage=path)

    if uri.scheme == 'carray':
        source = CArraySource(params=parms)
        structure = ARRAY

    elif uri.scheme == 'ctable':
        source = CTableSource(params=parms)
        structure = TABLE

    elif uri.scheme == 'sqlite':
        # Empty path means memory storage
        parms = params(storage=path or None)
        source = SqliteSource(params=parms)
        structure = TABLE

    else:
        # Default is to treat the URI as a regular path
        parms = params(storage=path)
        source = CArraySource(params=parms)
        structure = ARRAY

    # Don't want a deferred array (yet)
    # return NDArray(source)
    if structure == ARRAY:

        if eclass is _eclass.manifest:
            return Array(source)
        elif eclass is _eclass.delayed:
            return NDArray(source)

    elif structure == TABLE:

        if eclass is _eclass.manifest:
            return Table(source)
        elif eclass is _eclass.delayed:
            return NDTable(source)