Skip to content

Commit 82b9600

Browse files
authored
Merge pull request #764 from INM-6/fix/check_time
Fix for SpikeTrain consistency check encountering CompundUnits
2 parents 03bef5f + 9f2f265 commit 82b9600

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

neo/core/spiketrain.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ def check_has_dimensions_time(*values):
3838
'''
3939
errmsgs = []
4040
for value in values:
41-
dim = value.dimensionality
42-
if (len(dim) != 1 or list(dim.values())[0] != 1 or not isinstance(list(dim.keys())[0],
43-
pq.UnitTime)):
44-
errmsgs.append("value {} has dimensions {}, not [time]".format(value, dim.simplified))
41+
dim = value.dimensionality.simplified
42+
if (len(dim) != 1 or
43+
list(dim.values())[0] != 1 or not
44+
isinstance(list(dim.keys())[0], pq.UnitTime)):
45+
errmsgs.append(
46+
"value {} has dimensions {}, not [time]".format(
47+
value, dim))
4548
if errmsgs:
4649
raise ValueError("\n".join(errmsgs))
4750

neo/test/coretest/test_spiketrain.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ def test__check_has_dimensions_time(self):
143143
check_has_dimensions_time(d)
144144
self.assertRaises(ValueError, check_has_dimensions_time, a, b, c, d)
145145

146+
# Regression test for #763
147+
# This test ensures the function works for compound units
148+
def test__check_has_dimensions_time_compound_unit(self):
149+
a = np.arange(3) * pq.CompoundUnit("1/10*s")
150+
check_has_dimensions_time(a)
151+
146152

147153
class Testcheck_time_in_range(unittest.TestCase):
148154
def test__check_time_in_range_empty_array(self):

0 commit comments

Comments
 (0)