Skip to content

Commit 0649ac3

Browse files
committed
[MTag] adapt tests and do not throw an exception in tagged_data ...
the returned DataView will be invalid, though
1 parent 446f031 commit 0649ac3

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

nixio/multi_tag.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ def tagged_data(self, posidx, refidx, stop_rule=SliceMode.Exclusive):
139139
ref = references[refidx]
140140

141141
slices = self._calc_data_slices_mtag(ref, posidx, stop_rule)
142-
if not self._slices_in_data(ref, slices):
143-
raise OutOfBounds("References data slice out of the extent of the DataArray!")
144142
return DataView(ref, slices)
145143

146144
def retrieve_feature_data(self, posidx, featidx):

nixio/test/test_multi_tag.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Redistribution and use in section and binary forms, with or without
77
# modification, are permitted under the terms of the BSD License. See
88
# LICENSE file in the root of the Project.
9+
from nixio.exceptions.exceptions import InvalidSlice
910
import os
1011
import time
1112
import unittest
@@ -385,13 +386,16 @@ def test_multi_tag_tagged_data(self):
385386
assert np.array_equal(y_data[:2000], data[:])
386387

387388
# multi dimensional data
389+
# position 1 should fail since the position in the third dimension does not point to a valid point
390+
# positon 2 and 3 should deliver valid DataViews
391+
# same for segment 0 should again return an invalid DataView because of dimension 3
388392
sample_iv = 1.0
389393
ticks = [1.2, 2.3, 3.4, 4.5, 6.7]
390394
unit = "ms"
391-
pos = self.block.create_data_array("pos", "test", data=[[1, 1, 1], [1, 1, 1]])
395+
pos = self.block.create_data_array("pos", "test", data=[[1, 1, 1], [1, 1, 1.2], [1, 1, 1.2]])
392396
pos.append_set_dimension()
393397
pos.append_set_dimension()
394-
ext = self.block.create_data_array("ext", "test", data=[[1, 5, 2], [0, 4, 1]])
398+
ext = self.block.create_data_array("ext", "test", data=[[1, 5, 2], [1, 5, 2], [0, 4, 1]])
395399
ext.append_set_dimension()
396400
ext.append_set_dimension()
397401
units = ["none", "ms", "ms"]
@@ -414,20 +418,31 @@ def test_multi_tag_tagged_data(self):
414418
segtag.units = units
415419

416420
posdata = postag.tagged_data(0, 0)
421+
assert not posdata.valid
422+
assert "InvalidSlice error" in posdata.debug_message
423+
assert posdata.data_extent is None
424+
assert posdata.shape is None
425+
with self.assertRaises(InvalidSlice):
426+
posdata._write_data(np.random.randn(1))
427+
assert sum(posdata[:].shape) == 0
428+
429+
posdata = postag.tagged_data(1, 0)
430+
assert posdata.valid
431+
assert posdata.debug_message == ""
417432
assert len(posdata.shape) == 3
418433
assert posdata.shape == (1, 1, 1)
419434
assert np.isclose(posdata[0, 0, 0], data[1, 1, 0])
420435

421-
posdata = postag.tagged_data(1, 0)
436+
posdata = postag.tagged_data(2, 0)
422437
assert len(posdata.shape) == 3
423438
assert posdata.shape == (1, 1, 1)
424439
assert np.isclose(posdata[0, 0, 0], data[1, 1, 0])
425440

426-
segdata = segtag.tagged_data(0, 0)
441+
segdata = segtag.tagged_data(1, 0)
427442
assert len(segdata.shape) == 3
428443
assert segdata.shape == (1, 5, 2)
429444

430-
segdata = segtag.tagged_data(1, 0)
445+
segdata = segtag.tagged_data(2, 0)
431446
assert len(segdata.shape) == 3
432447
assert segdata.shape == (1, 4, 1)
433448

0 commit comments

Comments
 (0)