Repository: mne-tools/mne-python

Issue:
Minor: different errors for failure to preload?
This is a bit confusing:
`ValueError: Epochs must be preloaded to apply ICA`
`RuntimeError: raw.filter requires raw data to be loaded. Use preload=True (or string) in the constructor or raw.load_data().`

Maybe a preload-related failure should always give the same error (and always give the `inst.load_data()` hint).


Discussion:

Resolving patch:
diff --git a/mne/preprocessing/ica.py b/mne/preprocessing/ica.py
--- a/mne/preprocessing/ica.py
+++ b/mne/preprocessing/ica.py
@@ -48,7 +48,8 @@
 from ..utils import (check_version, logger, check_fname, verbose,
                      _reject_data_segments, check_random_state,
                      compute_corr, _get_inst_data, _ensure_int,
-                     copy_function_doc_to_method_doc, _pl, warn)
+                     copy_function_doc_to_method_doc, _pl, warn,
+                     _check_preload)
 
 from ..fixes import _get_args
 from ..filter import filter_data
@@ -1219,8 +1220,7 @@ def apply(self, inst, include=None, exclude=None, n_pca_components=None,
 
     def _apply_raw(self, raw, include, exclude, n_pca_components, start, stop):
         """Aux method."""
-        if not raw.preload:
-            raise ValueError('Raw data must be preloaded to apply ICA')
+        _check_preload(raw, "ica.apply")
 
         if exclude is None:
             exclude = list(set(self.exclude))
@@ -1245,8 +1245,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."""
-        if not epochs.preload:
-            raise ValueError('Epochs must be preloaded to apply ICA')
+        _check_preload(epochs, "ica.apply")
 
         picks = pick_types(epochs.info, meg=False, ref_meg=False,
                            include=self.ch_names,
diff --git a/mne/utils.py b/mne/utils.py
--- a/mne/utils.py
+++ b/mne/utils.py
@@ -2152,9 +2152,11 @@ def _check_preload(inst, msg):
     if isinstance(inst, BaseEpochs):
         name = 'epochs'
     if not inst.preload:
-        raise RuntimeError(msg + ' requires %s data to be loaded. Use '
-                           'preload=True (or string) in the constructor or '
-                           '%s.load_data().' % (name, name))
+        raise RuntimeError(
+            "By default, MNE does not load data into main memory to "
+            "conserve ressources. " + msg + ' requires %s data to be loaded. '
+            'Use preload=True (or string) in the constructor or '
+            '%s.load_data().' % (name, name))
 
 
 def _check_pandas_installed(strict=True):


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
@@ -232,7 +232,7 @@ def test_ica_core():
         # test preload filter
         raw3 = raw.copy()
         raw3.preload = False
-        assert_raises(ValueError, ica.apply, raw3,
+        assert_raises(RuntimeError, ica.apply, raw3,
                       include=[1, 2])
 
         #######################################################################
@@ -256,7 +256,7 @@ def test_ica_core():
         # test preload filter
         epochs3 = epochs.copy()
         epochs3.preload = False
-        assert_raises(ValueError, ica.apply, epochs3,
+        assert_raises(RuntimeError, ica.apply, epochs3,
                       include=[1, 2])
 
     # test for bug with whitener updating