From 68514e672dd04b0087fb87c1cf6ba8ee392ee8fb Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 16 Oct 2019 15:31:56 +0200 Subject: [PATCH 1/5] fix duplication of array_annotations into annotations --- neo/io/nixio.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/neo/io/nixio.py b/neo/io/nixio.py index d6302be3c..d3e662ffe 100644 --- a/neo/io/nixio.py +++ b/neo/io/nixio.py @@ -1190,14 +1190,15 @@ def _nix_attr_to_neo(nix_obj): values = "" elif len(values) == 1: values = values[0] - elif prop.definition == ARRAYANNOTATION: + else: + values = list(values) + if prop.definition == ARRAYANNOTATION: if 'array_annotations' in neo_attrs: neo_attrs['array_annotations'][prop.name] = values else: neo_attrs['array_annotations'] = {prop.name: values} else: - values = list(values) - neo_attrs[prop.name] = values + neo_attrs[prop.name] = values # since the 'neo_name' NIX property becomes the actual object's name, # there's no reason to keep it in the annotations neo_attrs["name"] = stringify(neo_attrs.pop("neo_name", None)) From 5e93d77b3dbda616b8aed16c881a11ae8de2ffa9 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 18 Oct 2019 09:30:19 +0200 Subject: [PATCH 2/5] removing redundant list conversion --- neo/io/nixio.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/neo/io/nixio.py b/neo/io/nixio.py index d3e662ffe..e04c87542 100644 --- a/neo/io/nixio.py +++ b/neo/io/nixio.py @@ -1190,8 +1190,6 @@ def _nix_attr_to_neo(nix_obj): values = "" elif len(values) == 1: values = values[0] - else: - values = list(values) if prop.definition == ARRAYANNOTATION: if 'array_annotations' in neo_attrs: neo_attrs['array_annotations'][prop.name] = values From e7f9fd2e11c4826dd4cc00c553e72fe71ae2d65e Mon Sep 17 00:00:00 2001 From: kleinjohann Date: Fri, 18 Oct 2019 11:57:41 +0200 Subject: [PATCH 3/5] Add test based on #748 --- neo/test/iotest/test_nixio.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/neo/test/iotest/test_nixio.py b/neo/test/iotest/test_nixio.py index 2913bf17e..f233bd779 100644 --- a/neo/test/iotest/test_nixio.py +++ b/neo/test/iotest/test_nixio.py @@ -787,6 +787,7 @@ def test_signals_write(self): asig = AnalogSignal(signal=self.rquant((19, 15), pq.mV), sampling_rate=pq.Quantity(10, "Hz")) + asig.array_annotate(arr_ann=np.random.random((15,))) seg.analogsignals.append(asig) self.write_and_compare([block]) @@ -1496,6 +1497,19 @@ def test_array_annotations_read(self): self.assertEqual(da.metadata.props['st_arr_ann'].unit, units_to_string(neo_ann.units)) + def test_read_blocks_are_writable(self): + filename = os.path.join(self.tempdir, "testnixio_out.nix") + writer = NixIO(filename, "ow") + + blocks = self.io.read_all_blocks() + + try: + writer.write_all_blocks(blocks) + except Exception as exc: + self.fail('The following exception was raised when' + + ' writing the blocks loaded with NixIO:\n' + + str(exc)) + @unittest.skipUnless(HAVE_NIX, "Requires NIX") class NixIOContextTests(NixIOTest): From 7ab59fa96015970fe05e0efef35727475c9f0cc7 Mon Sep 17 00:00:00 2001 From: kleinjohann Date: Fri, 18 Oct 2019 12:03:56 +0200 Subject: [PATCH 4/5] Remove unnecessary line --- neo/test/iotest/test_nixio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/neo/test/iotest/test_nixio.py b/neo/test/iotest/test_nixio.py index f233bd779..c2de2c48f 100644 --- a/neo/test/iotest/test_nixio.py +++ b/neo/test/iotest/test_nixio.py @@ -787,7 +787,6 @@ def test_signals_write(self): asig = AnalogSignal(signal=self.rquant((19, 15), pq.mV), sampling_rate=pq.Quantity(10, "Hz")) - asig.array_annotate(arr_ann=np.random.random((15,))) seg.analogsignals.append(asig) self.write_and_compare([block]) From 972f2ef33bfbe628fca1ca4e740d37316bb2be44 Mon Sep 17 00:00:00 2001 From: kleinjohann Date: Fri, 18 Oct 2019 12:11:10 +0200 Subject: [PATCH 5/5] Add missing comma for tuple creation --- neo/test/iotest/common_io_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/test/iotest/common_io_test.py b/neo/test/iotest/common_io_test.py index 02f739f4f..7f7987314 100644 --- a/neo/test/iotest/common_io_test.py +++ b/neo/test/iotest/common_io_test.py @@ -500,7 +500,7 @@ def test_assert_readed_neo_object_is_compliant(self): assert_neo_object_is_compliant(obj) # intercept exceptions and add more information except BaseException as exc: - exc.args += ('from %s' % os.path.basename(path)) + exc.args += ('from %s' % os.path.basename(path), ) raise def test_readed_with_lazy_is_compliant(self):