diff --git a/doc/changes/dev/14084.bugfix.rst b/doc/changes/dev/14084.bugfix.rst new file mode 100644 index 00000000000..fdacd1a7afb --- /dev/null +++ b/doc/changes/dev/14084.bugfix.rst @@ -0,0 +1 @@ +When concatenating :class:`~mne.io.Raw` objects containing annotations, also merge the ``extras`` fields, by `Marijn van Vliet`_ diff --git a/mne/annotations.py b/mne/annotations.py index e8ee5677e12..3d124be6a01 100644 --- a/mne/annotations.py +++ b/mne/annotations.py @@ -1750,7 +1750,10 @@ def _combine_annotations( duration = np.concatenate([one.duration, two.duration]) description = np.concatenate([one.description, two.description]) ch_names = np.concatenate([one.ch_names, two.ch_names]) - return Annotations(onset, duration, description, one.orig_time, ch_names) + extras = one.extras + two.extras + return Annotations( + onset, duration, description, one.orig_time, ch_names, extras=extras + ) def _handle_meas_date(meas_date): diff --git a/mne/tests/test_annotations.py b/mne/tests/test_annotations.py index 7c92780f3de..f19147b187c 100644 --- a/mne/tests/test_annotations.py +++ b/mne/tests/test_annotations.py @@ -86,6 +86,7 @@ def test_basics(): onset = np.array(range(10)) duration = np.ones(10) description = np.repeat("test", 10) + extras = [dict(foo=i) for i in range(10)] dt = raw.info["meas_date"] assert isinstance(dt, datetime) stamp = _dt_to_stamp(dt) @@ -110,7 +111,7 @@ def test_basics(): offset = offset[0] + offset[1] * 1e-6 offset = orig_time - offset assert_allclose(offset, raw._first_time) - annot = Annotations(onset, duration, description, orig_time) + annot = Annotations(onset, duration, description, orig_time, extras=extras) assert annot.orig_time is not None assert " segments" in repr(annot) raw2.set_annotations(annot) @@ -122,6 +123,7 @@ def test_basics(): assert_allclose(onset + offset + delta, raw.annotations.onset, rtol=1e-5) assert_array_equal(annot.duration, raw.annotations.duration) assert_array_equal(raw.annotations.description, np.repeat("test", 10)) + assert raw.annotations.extras == extras def test_annot_sanitizing(tmp_path):