Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
time_range=time_range,
time_selection=time_selection)
yield result
except GeneratorExit:
generator.throw(OutsideException(
"Terminating due to an exception originating from outside "
"strax's get_iter (which we cannot retrieve)."))
except Exception as e:
generator.throw(e)
raise
if not seen_a_chunk:
if time_range is None:
raise strax.DataCorrupted("No data returned!")
raise ValueError(f"Invalid time range: {time_range}, "
"returned no chunks!")
def _load_file(f, compressor, dtype):
try:
data = f.read()
if not len(data):
return np.zeros(0, dtype=dtype)
data = COMPRESSORS[compressor]['decompress'](data)
try:
return np.frombuffer(data, dtype=dtype)
except ValueError as e:
raise ValueError(f"ValueError while loading data with dtype =\n\t{dtype}") from e
except Exception:
raise strax.DataCorrupted(
f"Fatal Error while reading file {f}: "
+ strax.utils.formatted_exception())
def get_metadata(self, dirname):
prefix = dirname_to_prefix(dirname)
metadata_json = f'{prefix}-metadata.json'
md_path = osp.join(dirname, metadata_json)
if not osp.exists(md_path):
# Try old-format metadata
# (if it's not there, just let it raise FileNotFound
# with the usual message in the next stage)
old_md_path = osp.join(dirname, 'metadata.json')
if not osp.exists(old_md_path):
raise strax.DataCorrupted(f"Data in {dirname} has no metadata")
md_path = old_md_path
with open(md_path, mode='r') as f:
return json.loads(f.read())
def find_several(self, keys, **kwargs):
"""Return list with backend keys or False
for several data keys.
Options are as for find()
"""
# You can override this if the backend has a smarter way
# of checking availability (e.g. a single DB query)
result = []
for key in keys:
try:
r = self.find(key, **kwargs)
except (strax.DataNotAvailable,
strax.DataCorrupted):
r = False
result.append(r)
return result