Repository: mne-tools/mne-python

Issue:
ica.exclude does not support numpy array
If `ica.exclude` is a numpy array it breaks here:

https://github.com/mne-tools/mne-python/blob/ca35ce9923ae9dc02fe55d7b321f71337903a81b/mne/preprocessing/ica.py#L1368

```
import mne
import numpy as np
from mne.preprocessing import ICA, create_ecg_epochs
from mne.datasets import sample

data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'

raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.pick_types(meg=True, eeg=False, exclude='bads', stim=True)
raw.filter(1, 30, fir_design='firwin')

events = mne.find_events(raw, stim_channel='STI 014')
epochs = mne.Epochs(raw, events, event_id=None, tmin=-0.2, tmax=0.5, preload=True)

ica = ICA(n_components=0.95, method='fastica').fit(epochs)

####### This is the problem
ica.exclude = [0, 1, 2]  #This Works
# ica.exclude = np.array([0, 1, 2]) # This fails

_ = ica.apply(epochs) # This Breaks
```





Discussion:
I'll submit a PR and then we can discuss it.

Resolving patch:
diff --git a/mne/preprocessing/ica.py b/mne/preprocessing/ica.py
--- a/mne/preprocessing/ica.py
+++ b/mne/preprocessing/ica.py
@@ -1260,14 +1260,16 @@ def apply(self, inst, include=None, exclude=None, n_pca_components=None,
                              'type')
         return out
 
+    def _check_exclude(self, exclude):
+        if exclude is None:
+            return list(set(self.exclude))
+        else:
+            return list(set(self.exclude + exclude))
+
     def _apply_raw(self, raw, include, exclude, n_pca_components, start, stop):
         """Aux method."""
         _check_preload(raw, "ica.apply")
-
-        if exclude is None:
-            exclude = list(set(self.exclude))
-        else:
-            exclude = list(set(self.exclude + exclude))
+        exclude = self._check_exclude(exclude)
 
         if n_pca_components is not None:
             self.n_pca_components = n_pca_components
@@ -1288,6 +1290,7 @@ def _apply_raw(self, raw, include, exclude, n_pca_components, start, stop):
     def _apply_epochs(self, epochs, include, exclude, n_pca_components):
         """Aux method."""
         _check_preload(epochs, "ica.apply")
+        exclude = self._check_exclude(exclude)
 
         picks = pick_types(epochs.info, meg=False, ref_meg=False,
                            include=self.ch_names,
@@ -1317,6 +1320,7 @@ def _apply_epochs(self, epochs, include, exclude, n_pca_components):
 
     def _apply_evoked(self, evoked, include, exclude, n_pca_components):
         """Aux method."""
+        exclude = self._check_exclude(exclude)
         picks = pick_types(evoked.info, meg=False, ref_meg=False,
                            include=self.ch_names,
                            exclude='bads')


Test patch:
diff --git a/mne/preprocessing/tests/test_ica.py b/mne/preprocessing/tests/test_ica.py
--- a/mne/preprocessing/tests/test_ica.py
+++ b/mne/preprocessing/tests/test_ica.py
@@ -442,13 +442,14 @@ def test_ica_additional(method):
         assert_true(ica.pca_components_.shape == (4, len(picks)))
         assert_true(sources.shape[1] == ica.n_components_)
 
-        for exclude in [[], [0]]:
+        for exclude in [[], [0], np.array([1, 2, 3])]:
             ica.exclude = exclude
             ica.labels_ = {'foo': [0]}
             ica.save(test_ica_fname)
             ica_read = read_ica(test_ica_fname)
-            assert_true(ica.exclude == ica_read.exclude)
+            assert_true(list(ica.exclude) == ica_read.exclude)
             assert_equal(ica.labels_, ica_read.labels_)
+            ica.apply(raw)
             ica.exclude = []
             ica.apply(raw, exclude=[1])
             assert_true(ica.exclude == [])