Skip to content

Cannot resize `xindex` when appending array if `xindex` getter has been called

Created by: stefco

For some reason, calling the Series.xindex or, equivalently for timeseries, the TimeSeries.times getters causes problems when trying to append an array to another. I will look into this and try to fix it. If the getter is not called, appending works fine:

In [159]: t = TimeSeries.read('foo.hdf5')
     ...: # start = t.times[-1] + t.dt
     ...: # del start
     ...: start = 1175011260.0
     ...: # end = t.times[-1] + t.dt + Quantity(100, "s")
     ...: # del end
     ...: end = 1175011360.0
     ...: t2 = c.placeholder(t, start, end).copy()
     ...: t3 = t.append(t2)

In [160]: t = TimeSeries.read('foo.hdf5')
     ...: # start = t.times[-1] + t.dt
     ...: # del start
     ...: t.times
     ...: start = 1175011260.0
     ...: # end = t.times[-1] + t.dt + Quantity(100, "s")
     ...: # del end
     ...: end = 1175011360.0
     ...: t2 = c.placeholder(t, start, end).copy()
     ...: t3 = t.append(t2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/dev/gwpy/gwpy/types/series.py in append(self, other, gap, inplace, pad, resize)
    677                 try:
--> 678                     self.xindex.resize((s[0],), refcheck=False)
    679                 except ValueError as exc:

ValueError: cannot resize this array: it does not own its data

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-160-45fdee9ffe53> in <module>()
      8 end = 1175011360.0
      9 t2 = c.placeholder(t, start, end).copy()
---> 10 t3 = t.append(t2)

~/dev/gwpy/gwpy/types/series.py in append(self, other, gap, inplace, pad, resize)
    680                     if 'cannot resize' in str(exc):
    681                         self.xindex = self.xindex.copy()
--> 682                         self.xindex.resize((s[0],))
    683                     else:
    684                         raise

ValueError: cannot resize an array that references or is referenced
by another array in this way.  Use the resize function

In [161]: t = TimeSeries.read('foo.hdf5')
     ...: # start = t.times[-1] + t.dt
     ...: # del start
     ...: t.xindex
     ...: start = 1175011260.0
     ...: # end = t.times[-1] + t.dt + Quantity(100, "s")
     ...: # del end
     ...: end = 1175011360.0
     ...: t2 = c.placeholder(t, start, end).copy()
     ...: t3 = t.append(t2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/dev/gwpy/gwpy/types/series.py in append(self, other, gap, inplace, pad, resize)
    677                 try:
--> 678                     self.xindex.resize((s[0],), refcheck=False)
    679                 except ValueError as exc:

ValueError: cannot resize this array: it does not own its data

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-161-e6ed3fc215a6> in <module>()
      8 end = 1175011360.0
      9 t2 = c.placeholder(t, start, end).copy()
---> 10 t3 = t.append(t2)

~/dev/gwpy/gwpy/types/series.py in append(self, other, gap, inplace, pad, resize)
    680                     if 'cannot resize' in str(exc):
    681                         self.xindex = self.xindex.copy()
--> 682                         self.xindex.resize((s[0],))
    683                     else:
    684                         raise

ValueError: cannot resize an array that references or is referenced
by another array in this way.  Use the resize function