Repository: NeuralEnsemble/python-neo

Issue:
Regression in the `check_has_dimensions_time` method of the SpikeTrain class for Compound Units
Regression in the `check_has_dimensions_time` method of the SpikeTrain class.

Calling
`neo.SpikeTrain([1,2,3]*pq.CompoundUnit("1/10*s"), t_start=0*pq.ms, t_stop=10000*pq.s)-5*pq.CompoundUnit("1/100*s")`
used to issue
`ValueError: value 5.0 has dimensions s, not [time]`
due to an incorrect handling of CompoundUnits -- these need to be simplified first in order to check consistency.

This fixes the issue by an additional simplified statement, making the above statement return
`<SpikeTrain(array([0.5, 1.5, 2.5]) * (1/10*s), [-0.49999999999999994 (1/10*s), 99999.5 (1/10*s)])>`


Discussion:

Patch:
diff --git a/neo/core/spiketrain.py b/neo/core/spiketrain.py
index d863abb9..20a87594 100644
--- a/neo/core/spiketrain.py
+++ b/neo/core/spiketrain.py
@@ -38,10 +38,13 @@ def check_has_dimensions_time(*values):
     '''
     errmsgs = []
     for value in values:
-        dim = value.dimensionality
-        if (len(dim) != 1 or list(dim.values())[0] != 1 or not isinstance(list(dim.keys())[0],
-                                                                          pq.UnitTime)):
-            errmsgs.append("value {} has dimensions {}, not [time]".format(value, dim.simplified))
+        dim = value.dimensionality.simplified
+        if (len(dim) != 1 or
+                list(dim.values())[0] != 1 or not
+                isinstance(list(dim.keys())[0], pq.UnitTime)):
+            errmsgs.append(
+                "value {} has dimensions {}, not [time]".format(
+                    value, dim))
     if errmsgs:
         raise ValueError("\n".join(errmsgs))
 


Test patch:
diff --git a/neo/test/coretest/test_spiketrain.py b/neo/test/coretest/test_spiketrain.py
index b089ea24..325f9bc3 100644
--- a/neo/test/coretest/test_spiketrain.py
+++ b/neo/test/coretest/test_spiketrain.py
@@ -143,6 +143,12 @@ class Testcheck_has_dimensions_time(unittest.TestCase):
         check_has_dimensions_time(d)
         self.assertRaises(ValueError, check_has_dimensions_time, a, b, c, d)
 
+    # Regression test for #763
+    # This test ensures the function works for compound units
+    def test__check_has_dimensions_time_compound_unit(self):
+        a = np.arange(3) * pq.CompoundUnit("1/10*s")
+        check_has_dimensions_time(a)
+
 
 class Testcheck_time_in_range(unittest.TestCase):
     def test__check_time_in_range_empty_array(self):