Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Recursive funnction to load hdf5 data into a PyContainer()
Args:
py_container (PyContainer): Python container to load data into
h_group (h5 group or dataset): h5py object, group or dataset, to spider
and load all datasets.
"""
group_dtype = h5._hl.group.Group
dataset_dtype = h5._hl.dataset.Dataset
#either a file, group, or dataset
if isinstance(h_group, (H5FileWrapper, group_dtype)):
py_subcontainer = PyContainer()
try:
py_subcontainer.container_type = bytes(h_group.attrs['type'][0])
except KeyError:
raise
#py_subcontainer.container_type = ''
py_subcontainer.name = h_group.name
if py_subcontainer.container_type == b'dict_item':
py_subcontainer.key_type = h_group.attrs['key_type']
if py_subcontainer.container_type not in types_not_to_sort:
h_keys = sort_keys(h_group.keys())
else:
h_keys = h_group.keys()
for h_name in h_keys:
raise RuntimeError("Cannot open file. This file was likely"
" created with Python 2 and an old hickle version.")
# There is an unfortunate period of time where hickle 2.1.0 claims VERSION = int(3)
# For backward compatibility we really need to catch this.
# Actual hickle v3 files are versioned as A.B.C (e.g. 3.1.0)
elif VER_MAJOR == 3 and VER == VER_MAJOR:
if PY2:
warnings.warn("Hickle file appears to be old version (v2.1.0), attempting "
"legacy loading...")
from . import hickle_legacy2
return hickle_legacy2.load(fileobj, path=path, safe=safe)
else:
raise RuntimeError("Cannot open file. This file was likely"
" created with Python 2 and an old hickle version.")
elif VER_MAJOR >= 3:
py_container = PyContainer()
py_container.container_type = 'hickle'
py_container = _load(py_container, h_root_group)
return py_container[0][0]
except AssertionError:
if PY2:
warnings.warn("Hickle file is not versioned, attempting legacy loading...")
from . import hickle_legacy
return hickle_legacy.load(fileobj, safe)
else:
raise RuntimeError("Cannot open file. This file was likely"
" created with Python 2 and an old hickle version.")
finally:
# Close the file if requested.
# Closing a file twice will not cause any problems
if close_flag:
def __init__(self):
super(PyContainer, self).__init__()
self.container_type = None
self.name = None
self.key_type = None