Repository: NeuralEnsemble/python-neo

Issue:
t_start > t_stop issue in SpikeTrain
I am transferring the issue from https://github.com/NeuralEnsemble/elephant/issues/81 here. Is following intended? 

```python
import neo
import quantities as pq 
print(neo.SpikeTrain([]*pq.s, t_start=5*pq.s, t_stop=4*pq.s))
>>> [] s
``` 

I am on version `0.5.2`.
Shouldn't start and stop times in `neo.SpikeTrain` checked and an error thrown? 

Discussion:

Patch:
diff --git a/neo/core/spiketrain.py b/neo/core/spiketrain.py
index 5d285ae0..7256511b 100644
--- a/neo/core/spiketrain.py
+++ b/neo/core/spiketrain.py
@@ -54,6 +54,9 @@ def _check_time_in_range(value, t_start, t_stop, view=False):
     certain that the dtype and units are the same
     '''
 
+    if t_start > t_stop:
+        raise ValueError("t_stop (%s) is before t_start (%s)" % (t_stop, t_start))
+
     if not value.size:
         return
 
@@ -217,8 +220,8 @@ class SpikeTrain(BaseNeo, pq.Quantity):
         constructor, but not when slicing.
         '''
         if len(times) != 0 and waveforms is not None and len(times) != \
-                waveforms.shape[
-                    0]:  # len(times)!=0 has been used to workaround a bug occuring during neo import)
+                waveforms.shape[0]:
+            # len(times)!=0 has been used to workaround a bug occuring during neo import
             raise ValueError(
                 "the number of waveforms should be equal to the number of spikes")
 


Test patch:
diff --git a/neo/test/coretest/test_spiketrain.py b/neo/test/coretest/test_spiketrain.py
index 22dd0bc8..ed5cec3b 100644
--- a/neo/test/coretest/test_spiketrain.py
+++ b/neo/test/coretest/test_spiketrain.py
@@ -142,6 +142,12 @@ class Testcheck_time_in_range(unittest.TestCase):
         _check_time_in_range(value, t_start=t_start, t_stop=t_stop, view=False)
         _check_time_in_range(value, t_start=t_start, t_stop=t_stop, view=True)
 
+    def test__check_time_in_range_empty_array_invalid_t_stop(self):
+        value = np.array([])
+        t_start = 6 * pq.s
+        t_stop = 4 * pq.s
+        self.assertRaises(ValueError, _check_time_in_range, value, t_start=t_start, t_stop=t_stop)
+
     def test__check_time_in_range_exact(self):
         value = np.array([0., 5., 10.]) * pq.s
         t_start = 0. * pq.s
@@ -1558,7 +1564,7 @@ class TestPropertiesMethods(unittest.TestCase):
     def test__repr(self):
         result = repr(self.train1)
         if np.__version__.split(".")[:2] > ['1', '13']:
-            # see https://github.com/numpy/numpy/blob/master/doc/release/1.14.0-notes.rst#many-changes-to-array-printing-disableable-with-the-new-legacy-printing-mode
+            # see https://github.com/numpy/numpy/blob/master/doc/release/1.14.0-notes.rst#many-changes-to-array-printing-disableable-with-the-new-legacy-printing-mode  # nopep8
             targ = '<SpikeTrain(array([3., 4., 5.]) * ms, [0.5 ms, 10.0 ms])>'
         else:
             targ = '<SpikeTrain(array([ 3.,  4.,  5.]) * ms, [0.5 ms, 10.0 ms])>'
diff --git a/neo/test/iotest/test_nestio.py b/neo/test/iotest/test_nestio.py
index 155e3974..1686644d 100644
--- a/neo/test/iotest/test_nestio.py
+++ b/neo/test/iotest/test_nestio.py
@@ -673,8 +673,8 @@ class TestNestIO_Spiketrains(BaseTestIO, unittest.TestCase):
             filename='0gid-1time-1256-0.gdf',
             directory=self.local_test_dir, clean=False)
         r = NestIO(filenames=filename)
-        seg = r.read_segment(gid_list=[], t_start=400. * pq.ms,
-                             t_stop=1. * pq.ms)
+        seg = r.read_segment(gid_list=[], t_start=400.4 * pq.ms,
+                             t_stop=400.5 * pq.ms)
         for st in seg.spiketrains:
             self.assertEqual(st.size, 0)
 
@@ -689,7 +689,7 @@ class TestNestIO_Spiketrains(BaseTestIO, unittest.TestCase):
             directory=self.local_test_dir, clean=False)
         r = NestIO(filenames=filename)
         st = r.read_spiketrain(gdf_id=0, t_start=400. * pq.ms,
-                               t_stop=1. * pq.ms)
+                               t_stop=410. * pq.ms)
         self.assertEqual(st.size, 0)