Skip to content

Commit 94365b3

Browse files
Merge pull request #1051 from apdavison/fix-getitem-slice-none
Fix exception raised when calling pyplot.plot(sig.times, sig) if the signal has array annotations
2 parents 614c75d + 62bbc3c commit 94365b3

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

neo/core/analogsignal.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ def __getitem__(self, i):
265265
raise TypeError("%s not supported" % type(j))
266266
if isinstance(k, (int, np.integer)):
267267
obj = obj.reshape(-1, 1)
268+
elif k is None:
269+
# matplotlib _check_1d() calls__getitem__ with (:, None) and
270+
# reacts appropriately if an IndexError or ValueError is raised
271+
raise IndexError("Cannot add dimensions to an AnalogSignal")
268272
obj.array_annotate(**deepcopy(self.array_annotations_at_index(k)))
269273
elif isinstance(i, slice):
270274
obj = super().__getitem__(i)

neo/test/coretest/test_analogsignal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ def test__getitem_should_return_single_quantity(self):
639639
self.assertTrue(hasattr(self.signal1[9, 3], 'units'))
640640
self.assertRaises(IndexError, self.signal1.__getitem__, (99, 73))
641641

642+
def test__getitem__with_tuple_slice_none(self):
643+
self.assertRaises(IndexError, self.signal1.__getitem__, (slice(None), None))
644+
642645
def test__time_index(self):
643646
# scalar arguments
644647
self.assertEqual(self.signal2.time_index(2.0 * pq.s), 2)

0 commit comments

Comments
 (0)