Skip to content

Reading TimeSeries from empty Cache raises IndexError

Reading a TimeSeries from an empty glue.lal.Cache or list raises an IndexError:

>>> from gwpy.timeseries import TimeSeries
>>> TimeSeries.read([], 'test', format='gwf')
>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/registry.py", line 332, in read
    data = reader(*args, **kwargs)
  File "/Users/duncan/Library/Python/2.7/lib/python/site-packages/gwpy-0.1a10.dev833-py2.7.egg/gwpy/utils/deps.py", line 82, in wrapper
    return func(*args, **kwargs)
  File "/Users/duncan/Library/Python/2.7/lib/python/site-packages/gwpy-0.1a10.dev833-py2.7.egg/gwpy/timeseries/io/gwf/__init__.py", line 128, in read_timeseries
    return read_timeseriesdict(source, [channel], *args, **kwargs)[channel]
  File "/Users/duncan/Library/Python/2.7/lib/python/site-packages/gwpy-0.1a10.dev833-py2.7.egg/gwpy/timeseries/io/gwf/__init__.py", line 122, in read_timeseriesdict
    return reader(source, *args, **kwargs)
  File "/Users/duncan/Library/Python/2.7/lib/python/site-packages/gwpy-0.1a10.dev833-py2.7.egg/gwpy/utils/deps.py", line 82, in wrapper
    return func(*args, **kwargs)
  File "/Users/duncan/Library/Python/2.7/lib/python/site-packages/gwpy-0.1a10.dev833-py2.7.egg/gwpy/timeseries/io/gwf/framecpp.py", line 134, in read_timeseriesdict
    frametype = CacheEntry.from_T050017(filelist[0]).description
IndexError: list index out of range

While the error type is not an issue, the error cause is likely to confuse many users. The frametype setting should except an IndexError to allow the data reader to raise an exception (possibly ValueError or IndexError) with an error that mentions the empty cache.