Repository: gwastro/pycbc

Issue:
Slicing an array to return every other sample
There currently seems to be no way to do something like:

```
timeseries[::2]
```

with a pycbc TimeSeries.


Discussion:

Resolving patch:
diff --git a/pycbc/types/array.py b/pycbc/types/array.py
--- a/pycbc/types/array.py
+++ b/pycbc/types/array.py
@@ -711,9 +711,6 @@ def _getvalue(self, index):
     @_memoize_single
     @_returntype
     def _getslice(self, index):
-        if index.step is not None:
-            raise ValueError("Step size not supported for slicing")
-        
         return self._return(self._data[index])
     
     @_convert
diff --git a/pycbc/types/frequencyseries.py b/pycbc/types/frequencyseries.py
--- a/pycbc/types/frequencyseries.py
+++ b/pycbc/types/frequencyseries.py
@@ -115,6 +115,16 @@ def get_sample_frequencies(self):
     sample_frequencies = property(get_sample_frequencies,
                                   doc="Array of the sample frequencies.")
 
+    def _getslice(self, index):
+        if index.step is not None:
+            new_delta_f = self._delta_f * index.step
+        else:
+            new_delta_f = self._delta_f
+        return FrequencySeries(Array._getslice(self, index),
+                               delta_f=new_delta_f,
+                               epoch=self._epoch,
+                               copy=False)
+
     def __eq__(self,other):
         """
         This is the Python special method invoked whenever the '=='
diff --git a/pycbc/types/timeseries.py b/pycbc/types/timeseries.py
--- a/pycbc/types/timeseries.py
+++ b/pycbc/types/timeseries.py
@@ -94,20 +94,25 @@ def _typecheck(self, other):
             if self._epoch != other._epoch:
                 raise ValueError('different epoch')
 
-    def __getitem__(self, index):
-        if isinstance(index, slice):
-            # Set the new epoch---note that index.start may also be None
-            if self._epoch is None:
-                new_epoch = None
-            elif index.start is None:
-                new_epoch = self._epoch
-            else:
-                if index.start < 0:
-                    raise ValueError('Negative start index not supported')
-                new_epoch = self._epoch + index.start * self._delta_t
-            return TimeSeries(Array.__getitem__(self, index), self._delta_t, new_epoch, copy=False)
+    def _getslice(self, index):
+        # Set the new epoch---note that index.start may also be None
+        if self._epoch is None:
+            new_epoch = None
+        elif index.start is None:
+            new_epoch = self._epoch
+        else:
+            if index.start < 0:
+                raise ValueError('Negative start index not supported')
+            new_epoch = self._epoch + index.start * self._delta_t
+
+        if index.step is not None:
+            new_delta_t = self._delta_t * index.step
         else:
-            return Array.__getitem__(self, index)
+            new_delta_t = self._delta_t
+        
+        return TimeSeries(Array._getslice(self, index), new_delta_t,
+                          new_epoch, copy=False)
+
 
     def prepend_zeros(self, num):
         """Prepend num zeros onto the beginning of this TimeSeries. Update also


Test patch: