Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data = numpy.asarray(data, order="C", dtype=dtype)
dtype = data.dtype
self.log.info("data dtype: {}".format(data.dtype))
# Validate shape
if shape is None:
if data is None:
raise TypeError("Either data or shape must be specified")
shape = data.shape
else:
shape = tuple(shape)
if data is not None and (numpy.product(shape) != numpy.product(data.shape)):
raise ValueError("Shape tuple is incompatible with data")
dsid = dataset.make_new_dset(self, shape=shape, dtype=dtype, **kwds)
dset = dataset.Dataset(dsid)
if data is not None:
self.log.info("initialize data")
dset[...] = data
if name is not None:
items = name.split('/')
path = []
for item in items:
if len(item) > 0:
path.append(item) # just get non-empty strings
grp = self
if len(path) == 0:
# no name, just return anonymous dataset
return dset
def __len__(self):
''' Number of dimensions associated with the dataset. '''
return len(Dataset(self._id).shape)
read_count = nrows - indx
if self._query is None:
arr = self._table[indx:read_count+indx]
else:
# call table to return query result
if query_complete:
arr = None # nothing more to fetch
else:
arr = self._table.read_where(self._query, start=indx, limit=read_count)
if arr is not None and arr.shape[0] < read_count:
query_complete = True # we've gotten all the rows
if arr is not None and indx%BUFFER_SIZE < arr.shape[0]:
yield arr[indx%BUFFER_SIZE]
class Table(Dataset):
"""
Represents an HDF5 dataset
"""
def __init__(self, bind):
""" Create a new Table object by binding to a low-level DatasetID.
"""
if not isinstance(bind, DatasetID):
raise ValueError("%s is not a DatasetID" % bind)
Dataset.__init__(self, bind)
if len(self._dtype) < 1:
raise ValueError("Table type must be compound")
if len(self._shape) > 1:
def label(self, val):
# pylint: disable=missing-docstring
dset = Dataset(self._id)
req = dset.attrs._req_prefix + 'DIMENSION_LABELS'
try:
labels = dset.GET(req)
dset.DELETE(req)
except IOError:
rank = len(dset.shape)
labels = {
'shape': {
'class': 'H5S_SIMPLE',
'dims': [rank]
},
'type': {
'class': 'H5T_STRING',
'charSet': 'H5T_CSET_UTF8',
'length': 'H5T_VARIABLE',
'strPad': 'H5T_STR_NULLTERM'
def __init__(self, bind):
""" Create a new Table object by binding to a low-level DatasetID.
"""
if not isinstance(bind, DatasetID):
raise ValueError("%s is not a DatasetID" % bind)
Dataset.__init__(self, bind)
if len(self._dtype) < 1:
raise ValueError("Table type must be compound")
if len(self._shape) > 1:
raise ValueError("Table must be one-dimensional")
def detach_scale(self, dscale):
''' Remove a scale from this dimension.
Provide the Dataset of the scale you would like to remove.
'''
dset = Dataset(self._id)
req = dset.attrs._req_prefix + 'DIMENSION_LIST'
dimlist = dset.GET(req)
dset.DELETE(req)
try:
ref = 'datasets/' + dscale.id.id
dimlist['value'][self._dimension].remove(ref)
except Exception as e:
# Restore the attribute's old value then raise the same
# exception
dset.PUT(req, body=dimlist)
raise e
dset.PUT(req, body=dimlist)
req = dscale.attrs._req_prefix + 'REFERENCE_LIST'
old_reflist = dscale.GET(req)
if "value" in old_reflist and len(old_reflist["value"]) > 0: