def infer_datashape(source): if isinstance(source, np.ndarray): return from_numpy(source.shape, source.dtype) elif isinstance(source, list): # TODO: um yeah, we'd don't actually want to do this cast = np.array(source) return from_numpy(cast.shape, cast.dtype) else: return dynamic
def infer_datashape(source): """ The user has only provided us with a Python object ( could be a buffer interface, a string, a list, list of lists, etc) try our best to infer what the datashape should be in the context of this datasource. """ if isinstance(source, np.ndarray): return from_numpy(source.shape, source.dtype) elif isinstance(source, list): # TODO: um yeah, we'd don't actually want to do this cast = np.array(source) return from_numpy(cast.shape, cast.dtype) else: return dynamic
def empty(self, dshape): """ Create a CArraySource from a datashape specification, downcasts into Numpy dtype and shape tuples if possible otherwise raises an exception. """ shape, dtype = from_numpy(dshape) return CArraySource(carray([], dtype))
def __init__(self, data=None, dshape=None, params=None): # need at least one of the three assert (data is not None) or (dshape is not None) or \ (params.get('storage')) # Extract the relevant carray parameters from the more # general Blaze params object. if params: cparams, rootdir, format_flavor = to_cparams(params) else: rootdir, cparams = None, None if isinstance(data, CArraySource): data = data.ca dshape = dshape if dshape else data.dshape if dshape: shape, dtype = to_numpy(dshape) self.ca = carray.carray(data, dtype=dtype, rootdir=rootdir, cparams=cparams) self.dshape = dshape else: self.ca = carray.carray(data, rootdir=rootdir, cparams=cparams) self.dshape = from_numpy(self.ca.shape, self.ca.dtype)
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
def __init__(self, data=None, dshape=None, params=None): # need at least one of the three assert (data is not None) or (dshape is not None) or \ (params.get('storage')) # Extract the relevant carray parameters from the more # general Blaze params object. if params: cparams, rootdir, format_flavor = to_cparams(params) else: rootdir,cparams = None, None if dshape: shape, dtype = to_numpy(dshape) self.ca = carray.carray(data, dtype=dtype, rootdir=rootdir, cparams=cparams) self.dshape = dshape else: self.ca = carray.carray(data, rootdir=rootdir, cparams=cparams) self.dshape = from_numpy(self.ca.shape, self.ca.dtype)
def empty(self, datashape): shape, dtype = from_numpy(datashape) return ArraySource(np.ndarray(shape, dtype))
def empty(self, dshape): shape, dtype = from_numpy(dshape) return CTableSource(carray([[]], dtype))
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)
def append(self, data): self.data.ca.append(data) # Update the shape shape, dtype = self.data.ca.shape, self.data.ca.dtype self._datashape = from_numpy(shape, dtype)