Esempio n. 1
0
def test_open_ctable():
    with temp_dir() as temp:
        # Create an table on disk
        table_filename = os.path.join(temp, 'ctable')
        p = params(storage=table_filename)
        ds = dshape('1,{ x: int32; y: int32 }')
        t = CTableSource(data=[(1, 1), (2, 2)], dshape=ds, params=p)
        del t

        # Open table with open function
        uri = 'ctable://' + table_filename
        c = toplevel.open(uri)
        assert c.datashape == ds

        # Test delayed mode
        c = toplevel.open(uri, eclass=eclass.delayed)
        assert c.datashape == ds
Esempio n. 2
0
    def __init__(self,
                 data,
                 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(data)
        else:
            # The user overlayed their custom dshape on this
            # data, check if it makes sense
            CTableSource.check_datashape(data, given_dshape=dshape)
            self._datashape = dshape

        # Source
        # ------

        if isinstance(data, ByteProvider):
            self.data = data
        if isinstance(data, dict):
            ct = self.from_dict(data)
            self._axes = data.keys()

            dshape = from_numpy(ct.shape, ct.dtype)
            self.data = CTableSource(ct, dshape=dshape, params=params)
            self._datashape = dshape
        elif isinstance(data, (list, tuple)):
            self.data = CTableSource(data, dshape=dshape, params=params)
            # Pull the labels from the datashape
            self._axes = self._datashape[-1].names
        else:
            raise ValueError

        # 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
Esempio n. 3
0
 def __getitem__(self, mask):
     ct = (self.data.ca[mask])
     dshape = from_numpy(ct.shape, ct.dtype)
     source = CTableSource(ct, dshape=dshape)
     return Table(source, dshape=dshape)