Skip to content

Commit 0274b40

Browse files
authored
Merge pull request #941 from shashwatsridhar/fix/#940_fix_create_group_across_segment
Fix multiples errors in BaseFromRaw.read_block()
2 parents b42c10b + 76bd600 commit 0274b40

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

doc/source/authors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ and may not be the current affiliation of a contributor.
5353
* Hugo van Kemenade
5454
* Aitor Morales-Gregorio [13]
5555
* Peter N Steinmetz [22]
56+
* Shashwat Sridhar
5657
* Alessio Buccino [23]
5758

5859
1. Centre de Recherche en Neuroscience de Lyon, CNRS UMR5292 - INSERM U1028 - Universite Claude Bernard Lyon 1

neo/io/basefromrawio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def read_block(self, block_index=0, lazy=False,
123123
create_group_across_segment = { k: v for k in l}
124124
elif isinstance(create_group_across_segment, dict):
125125
# put False to missing keys
126-
create_group_across_segment = {create_group_across_segment.get(k, False) for k in l}
126+
create_group_across_segment = {k: create_group_across_segment.get(k, False) for k in l}
127127
else:
128128
raise ValueError('create_group_across_segment must be bool or dict')
129129

@@ -153,12 +153,12 @@ def read_block(self, block_index=0, lazy=False,
153153
unit_channels = self.header['unit_channels']
154154
st_groups = []
155155
for c in range(unit_channels.size):
156-
group = Group(name='SpikeTrain group {}'.format(i))
156+
group = Group(name='SpikeTrain group {}'.format(c))
157157
group.annotate(unit_name=unit_channels[c]['name'])
158158
group.annotate(unit_id=unit_channels[c]['id'])
159159
unit_annotations = self.raw_annotations['unit_channels'][c]
160160
unit_annotations = check_annotations(unit_annotations)
161-
group.annotations.annotate(**unit_annotations)
161+
group.annotate(**unit_annotations)
162162
bl.groups.append(group)
163163
st_groups.append(group)
164164

neo/test/iotest/common_io_test.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
__test__ = False
1919

2020
import os
21+
import inspect
2122
from copy import copy
2223
import unittest
2324

2425
from neo.core import Block, Segment
26+
from neo.io.basefromrawio import BaseFromRaw
2527
from neo.test.tools import (assert_same_sub_schema,
2628
assert_neo_object_is_compliant,
2729
assert_sub_schema_is_lazy_loaded,
@@ -154,7 +156,7 @@ def able_to_write_or_read(self, writeread=False, readwrite=False):
154156
# sampling_rate (RawBinaryIO...) the test is too much complex to design
155157
# genericaly.
156158
if (self.higher in self.ioclass.read_params and
157-
len(self.ioclass.read_params[self.higher]) != 0):
159+
len(self.ioclass.read_params[self.higher]) != 0):
158160
return False
159161

160162
# handle cases where the test should write then read
@@ -511,3 +513,48 @@ def test_readed_with_lazy_is_compliant(self):
511513
# intercept exceptions and add more information
512514
except BaseException as exc:
513515
raise
516+
517+
def test_create_group_across_segment(self):
518+
"""
519+
Read {io_name} files in 'files_to_test' with
520+
create_group_across_segment test cases.
521+
522+
Test read_block method of BaseFromRaw with different test cases
523+
for create_group_across_segment.
524+
525+
""".format(io_name=self.ioclass.__name__)
526+
527+
test_cases = [
528+
{"SpikeTrain": True},
529+
{"AnalogSignal": True},
530+
{"Event": True},
531+
{"Epoch": True},
532+
{"SpikeTrain": True,
533+
"AnalogSignal": True,
534+
"Event": True,
535+
"Epoch": True},
536+
True
537+
]
538+
expected_outcomes = [
539+
None,
540+
None,
541+
NotImplementedError,
542+
NotImplementedError,
543+
NotImplementedError,
544+
NotImplementedError,
545+
]
546+
547+
mock_test_case = unittest.TestCase()
548+
if issubclass(self.ioclass, BaseFromRaw):
549+
for obj, reader in self.iter_objects(target=Block,
550+
lazy=self.ioclass.support_lazy,
551+
return_reader=True):
552+
if "create_group_across_segment" in inspect.signature(reader).parameters.keys():
553+
# Ignore testing readers for IOs where read_block is overridden to exclude
554+
# the create_group_across_segment functionality, for eg. NixIO_fr
555+
for case, outcome in zip(test_cases, expected_outcomes):
556+
if outcome is not None:
557+
with mock_test_case.assertRaises(outcome):
558+
reader(lazy=self.ioclass.support_lazy, create_group_across_segment=case)
559+
else:
560+
reader(lazy=self.ioclass.support_lazy, create_group_across_segment=case)

0 commit comments

Comments
 (0)