Repository: mne-tools/mne-python

Issue:
BUG: mne.channels.combine_channels does not preserve events
Related to #8014

#### Describe the bug
When using the function [combine_channels](https://mne.tools/dev/generated/mne.channels.combine_channels.html) on an Epochs object, the output loses the events.


#### Steps to reproduce
```python
import os.path as op

from mne.io import read_raw_fif
from mne import read_events, Epochs
from mne.channels import combine_channels


io_dir = op.join(op.dirname(__file__), 'mne', 'io')
base_dir = op.join(io_dir, 'tests', 'data')
raw_fname = op.join(base_dir, 'test_raw.fif')
eve_fname = op .join(base_dir, 'test-eve.fif')

raw = read_raw_fif(raw_fname, preload=True)
epochs = Epochs(raw, read_events(eve_fname))

roi_dict = dict(foo=[0, 1], bar=[5, 2])
combined_epochs = combine_channels(epochs, roi_dict)

print(combined_epochs.events)
```


#### Expected results
```
[[27977     0     2]
 [28345     0     3]
 [28771     0     1]
 [29219     0     4]
 [29652     0     2]
 [30025     0     3]
 [30450     0     1]
 [30839     0     4]
 [31240     0     2]
 [31665     0     3]
 [32101     0     1]
 [32519     0     4]
 [32935     0     2]
 [33325     0     3]
 [33712     0     1]
 [34089     0     5]
 [34532     0     2]
 [34649     0    32]
 [34956     0     3]
 [35428     0     1]
 [35850     0     4]
 [36211     0     2]
 [36576     0     3]
 [37007     0     1]
 [37460     0     4]
 [37910     0     2]
 [38326     0     3]
 [38711     0     1]
 [39130     0     4]
 [39563     0     2]]
```


#### Actual results
```
[[ 0  0  1]
 [ 1  0  1]
 [ 2  0  1]
 [ 3  0  1]
 [ 4  0  1]
 [ 5  0  1]
 [ 6  0  1]
 [ 7  0  1]
 [ 8  0  1]
 [ 9  0  1]
 [10  0  1]
 [11  0  1]
 [12  0  1]
 [13  0  1]
 [14  0  1]
 [15  0  1]
 [16  0  1]
 [17  0  1]
 [18  0  1]
 [19  0  1]
 [20  0  1]
 [21  0  1]
 [22  0  1]
 [23  0  1]
 [24  0  1]
 [25  0  1]
 [26  0  1]
 [27  0  1]
 [28  0  1]
 [29  0  1]]
```



Discussion:
I'll work on a fix 🙂

Resolving patch:
diff --git a/mne/channels/channels.py b/mne/channels/channels.py
--- a/mne/channels/channels.py
+++ b/mne/channels/channels.py
@@ -1730,8 +1730,8 @@ def combine_channels(inst, groups, method='mean', keep_stim=False,
         combined_inst = RawArray(new_data, info, first_samp=inst.first_samp,
                                  verbose=inst.verbose)
     elif isinstance(inst, BaseEpochs):
-        combined_inst = EpochsArray(new_data, info, tmin=inst.times[0],
-                                    verbose=inst.verbose)
+        combined_inst = EpochsArray(new_data, info, events=inst.events,
+                                    tmin=inst.times[0], verbose=inst.verbose)
     elif isinstance(inst, Evoked):
         combined_inst = EvokedArray(new_data, info, tmin=inst.times[0],
                                     verbose=inst.verbose)


Test patch:
diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py
--- a/mne/channels/tests/test_channels.py
+++ b/mne/channels/tests/test_channels.py
@@ -372,7 +372,8 @@ def test_combine_channels():
 
     # Test good cases
     combine_channels(raw, good)
-    combine_channels(epochs, good)
+    combined_epochs = combine_channels(epochs, good)
+    assert_array_equal(combined_epochs.events, epochs.events)
     combine_channels(evoked, good)
     combine_channels(raw, good, drop_bad=True)
     combine_channels(raw_ch_bad, good, drop_bad=True)
@@ -390,12 +391,12 @@ def test_combine_channels():
     foo_mean = np.mean(raw.get_data()[good_single['foo']], axis=0)
     foo_median = np.median(raw.get_data()[good_single['foo']], axis=0)
     foo_std = np.std(raw.get_data()[good_single['foo']], axis=0)
-    assert np.array_equal(combined_mean.get_data(),
-                          np.expand_dims(foo_mean, axis=0))
-    assert np.array_equal(combined_median.get_data(),
-                          np.expand_dims(foo_median, axis=0))
-    assert np.array_equal(combined_std.get_data(),
-                          np.expand_dims(foo_std, axis=0))
+    assert_array_equal(combined_mean.get_data(),
+                       np.expand_dims(foo_mean, axis=0))
+    assert_array_equal(combined_median.get_data(),
+                       np.expand_dims(foo_median, axis=0))
+    assert_array_equal(combined_std.get_data(),
+                       np.expand_dims(foo_std, axis=0))
 
     # Test bad cases
     bad1 = dict(foo=[0, 376], bar=[5, 2])  # out of bounds