Skip to content

Commit 85cd56b

Browse files
wmvanvlietPragnyaKhandelwal
authored andcommitted
Make _combine_annotations also merge extras (#14084)
1 parent 3643fc3 commit 85cd56b

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

doc/changes/dev/14084.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When concatenating :class:`~mne.io.Raw` objects containing annotations, also merge the ``extras`` fields, by `Marijn van Vliet`_

mne/annotations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,10 @@ def _combine_annotations(
17501750
duration = np.concatenate([one.duration, two.duration])
17511751
description = np.concatenate([one.description, two.description])
17521752
ch_names = np.concatenate([one.ch_names, two.ch_names])
1753-
return Annotations(onset, duration, description, one.orig_time, ch_names)
1753+
extras = one.extras + two.extras
1754+
return Annotations(
1755+
onset, duration, description, one.orig_time, ch_names, extras=extras
1756+
)
17541757

17551758

17561759
def _handle_meas_date(meas_date):

mne/tests/test_annotations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def test_basics():
8686
onset = np.array(range(10))
8787
duration = np.ones(10)
8888
description = np.repeat("test", 10)
89+
extras = [dict(foo=i) for i in range(10)]
8990
dt = raw.info["meas_date"]
9091
assert isinstance(dt, datetime)
9192
stamp = _dt_to_stamp(dt)
@@ -110,7 +111,7 @@ def test_basics():
110111
offset = offset[0] + offset[1] * 1e-6
111112
offset = orig_time - offset
112113
assert_allclose(offset, raw._first_time)
113-
annot = Annotations(onset, duration, description, orig_time)
114+
annot = Annotations(onset, duration, description, orig_time, extras=extras)
114115
assert annot.orig_time is not None
115116
assert " segments" in repr(annot)
116117
raw2.set_annotations(annot)
@@ -122,6 +123,7 @@ def test_basics():
122123
assert_allclose(onset + offset + delta, raw.annotations.onset, rtol=1e-5)
123124
assert_array_equal(annot.duration, raw.annotations.duration)
124125
assert_array_equal(raw.annotations.description, np.repeat("test", 10))
126+
assert raw.annotations.extras == extras
125127

126128

127129
def test_annot_sanitizing(tmp_path):

0 commit comments

Comments
 (0)