Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
store_flags = instance._store_flags()
except AttributeError:
store_flags = {}
self._prm_extract_missing_flags(store_dict,store_flags)
for key, data_to_store in store_dict.items():
if (not instance.v_is_parameter or msg == pypetconstants.LEAF) and key in _hdf5_group:
self._logger.debug('Found %s already in hdf5 node of %s, so I will ignore it.' %
(key, fullname))
continue
if store_flags[key] == HDF5StorageService.TABLE:
self._prm_store_into_pytable(msg,key, data_to_store, _hdf5_group, fullname)
elif key in _hdf5_group:
self._logger.debug('Found %s already in hdf5 node of %s, so I will ignore it.' %
(key, fullname))
continue
elif store_flags[key] == HDF5StorageService.DICT:
self._prm_store_dict_as_table(msg,key, data_to_store, _hdf5_group, fullname)
elif store_flags[key] == HDF5StorageService.ARRAY:
self._prm_store_into_array(msg,key, data_to_store, _hdf5_group, fullname)
elif store_flags[key] == HDF5StorageService.CARRAY:
self._prm_store_into_carray(msg,key, data_to_store, _hdf5_group, fullname)
elif store_flags[key] == HDF5StorageService.FRAME:
self._prm_store_data_frame(msg,key, data_to_store, _hdf5_group, fullname)
else:
raise RuntimeError('You shall not pass!')
annotated = self._all_get_from_attrs(node,HDF5StorageService.ANNOTATED)
if annotated:
annotations =item_with_annotations.v_annotations
if not annotations.f_is_empty():
raise TypeError('Loading into non-empty annotations!')
current_attrs = node._v_attrs
for attr_name in current_attrs._v_attrnames:
if attr_name.startswith(HDF5StorageService.ANNOTATION_PREFIX):
key = attr_name
key=key.replace(HDF5StorageService.ANNOTATION_PREFIX,'')
data = getattr(current_attrs,attr_name)
setattr(annotations,key,data)
try:
table_name = self._all_get_table_name(where,instance.v_creator_name)
table = getattr(self._overview_group,table_name)
self._all_store_param_or_result_table_entry(instance,table,
flags=flags)
except pt.NoSuchNodeError:
pass
if not self._purge_duplicate_comments or definitely_store_comment:
setattr(group._v_attrs, HDF5StorageService.COMMENT, instance.v_comment)
setattr(group._v_attrs, HDF5StorageService.CLASS_NAME, instance.f_get_class_name())
setattr(group._v_attrs,HDF5StorageService.LEAF,1)
if instance.v_is_parameter and instance.f_has_range():
setattr(group._v_attrs, HDF5StorageService.LENGTH,len(instance))
try:
tablename = 'explored_parameters'
table = getattr(self._overview_group,tablename)
self._all_store_param_or_result_table_entry(instance,table,
flags=flags)
except pt.NoSuchNodeError:
pass
elif type(data) is list:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_LIST)
elif type(data) is np.ndarray:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_NDARRAY)
elif type(data) is np.matrix:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_MATRIX)
elif type(data) in pypetconstants.PARAMETER_SUPPORTED_DATA:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_SCALAR)
strtype = repr(type(data))
if not strtype in pypetconstants.PARAMETERTYPEDICT:
raise TypeError('I do not know how to handel `%s` its type is `%s`.' %
(str(data),repr(type(data))))
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.SCALAR_TYPE,strtype)
elif type(data) is dict:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_DICT)
else:
raise TypeError('I do not know how to handel `%s` its type is `%s`.' %
(str(data),repr(type(data))))
def _prm_read_table(self,table,load_dict, full_name):
''' Reads a non-nested Pytables table column by column.
:type table: pt.Table
:type load_dict:
:return:
'''
try:
table_name = table._v_name
for colname in table.colnames:
col = table.col(colname)
data_list=list(col)
prefix = HDF5StorageService.FORMATTED_COLUMN_PREFIX % colname
for idx,data in enumerate(data_list):
data,type_changed = self._all_recall_native_type(data,table,prefix)
if type_changed:
data_list[idx] = data
else:
break
if table_name in load_dict:
load_dict[table_name][colname] = data_list
else:
load_dict[table_name] = ObjectTable(data={colname:data_list})
except:
self._logger.error('Failed loading `%s` of `%s`.' % (table._v_name,full_name))
raise
# if new_name is None and new_filename is None:
# raise ValueError('Calling `f_migrate` without changing at least one thing makes no sense.')
#
# if new_name is not None and new_name == self._name:
# raise ValueError('New name must differ from old one.')
#
# if new_filename is not None and new_filename == self._filename:
# raise ValueError('New filename must differ from old one.')
if new_name is not None:
self._name = new_name
self._trajectory_name = self._name
if new_filename is not None:
if self._storage_service is None:
self._storage_service = HDF5StorageService(filename=new_filename, file_title=new_filename)
else:
self._storage_service.filename = new_filename
self._filename = new_filename
self._stored = in_store
if type(data) is tuple:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_TUPLE)
elif type(data) is list:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_LIST)
elif type(data) is np.ndarray:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_NDARRAY)
elif type(data) is np.matrix:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_MATRIX)
elif type(data) in pypetconstants.PARAMETER_SUPPORTED_DATA:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_SCALAR)
strtype = repr(type(data))
if not strtype in pypetconstants.PARAMETERTYPEDICT:
raise TypeError('I do not know how to handel `%s` its type is `%s`.' %
(str(data),repr(type(data))))
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.SCALAR_TYPE,strtype)
elif type(data) is dict:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_DICT)
elif not condition is None:
row_iterator = table.where(condition,condvars=condvars)
elif not index is None:
row_iterator = table.iterrows(index,index+1)
else:
row_iterator = None
try:
row = row_iterator.next()
except AttributeError:
row = None
except StopIteration:
row = None
if ((HDF5StorageService.MODIFY_ROW in flags or HDF5StorageService.ADD_ROW in flags) and
HDF5StorageService.REMOVE_ROW in flags):
raise ValueError('You cannot add or modify and remove a row at the same time.')
if row is None and HDF5StorageService.ADD_ROW in flags:
row = table.row
self._all_insert_into_row(row,insert_dict)
row.append()
elif (row is not None and HDF5StorageService.MODIFY_ROW in flags):
self._all_insert_into_row(row,insert_dict)
except AttributeError:
item_or_dict._f_setAttr(name,val)
except AttributeError:
item_or_dict[name]=val
if type(data) is tuple:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_TUPLE)
elif type(data) is list:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_LIST)
elif type(data) is np.ndarray:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_NDARRAY)
elif type(data) is np.matrix:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_MATRIX)
elif type(data) in pypetconstants.PARAMETER_SUPPORTED_DATA:
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.COLL_TYPE,
HDF5StorageService.COLL_SCALAR)
strtype = repr(type(data))
if not strtype in pypetconstants.PARAMETERTYPEDICT:
raise TypeError('I do not know how to handel `%s` its type is `%s`.' %
(str(data),repr(type(data))))
_set_attribute_to_item_or_dict(ptitem_or_dict,prefix+HDF5StorageService.SCALAR_TYPE,strtype)
for key, data_to_store in store_dict.items():
if (not instance.v_is_parameter or msg == pypetconstants.LEAF) and key in _hdf5_group:
self._logger.debug('Found %s already in hdf5 node of %s, so I will ignore it.' %
(key, fullname))
continue
if store_flags[key] == HDF5StorageService.TABLE:
self._prm_store_into_pytable(msg,key, data_to_store, _hdf5_group, fullname)
elif key in _hdf5_group:
self._logger.debug('Found %s already in hdf5 node of %s, so I will ignore it.' %
(key, fullname))
continue
elif store_flags[key] == HDF5StorageService.DICT:
self._prm_store_dict_as_table(msg,key, data_to_store, _hdf5_group, fullname)
elif store_flags[key] == HDF5StorageService.ARRAY:
self._prm_store_into_array(msg,key, data_to_store, _hdf5_group, fullname)
elif store_flags[key] == HDF5StorageService.CARRAY:
self._prm_store_into_carray(msg,key, data_to_store, _hdf5_group, fullname)
elif store_flags[key] == HDF5StorageService.FRAME:
self._prm_store_data_frame(msg,key, data_to_store, _hdf5_group, fullname)
else:
raise RuntimeError('You shall not pass!')