Repository: nilearn/nilearn

Issue:
Drop Scikit Learn < 0.15

Whats new doc says: "Dropped support for scikit-learn 0.14 Minimum supported version is now 0.15".

What I see from version.py is minimum required is 0.14.1.
https://github.com/nilearn/nilearn/blob/master/nilearn/version.py

and from travis
https://github.com/nilearn/nilearn/blob/master/.travis.yml

Question: According to doc string, minimum version should be changed to 0.15 or doc string needs to be changed ?


Discussion:
Good point, this should be changed.

I suggest to release 0.3 first (we're in the beta window, and we've been
in the beta window too long) and fix this after.


Resolving patch:
diff --git a/nilearn/_utils/cache_mixin.py b/nilearn/_utils/cache_mixin.py
--- a/nilearn/_utils/cache_mixin.py
+++ b/nilearn/_utils/cache_mixin.py
@@ -230,9 +230,6 @@ def cache(func, memory, func_memory_level=None, memory_level=None,
         memory = Memory(cachedir=None, verbose=verbose)
     cached_func = _safe_cache(memory, func, **kwargs)
     if shelve:
-        if LooseVersion(sklearn.__version__) < LooseVersion('0.15'):
-            raise ValueError('Shelving is only available if'
-                             ' scikit-learn >= 0.15 is installed.')
         cached_func = _ShelvedFunc(cached_func)
     return cached_func
 
diff --git a/nilearn/version.py b/nilearn/version.py
--- a/nilearn/version.py
+++ b/nilearn/version.py
@@ -38,7 +38,7 @@
         'required_at_installation': True,
         'install_info': _NILEARN_INSTALL_MSG}),
     ('sklearn', {
-        'min_version': '0.14.1',
+        'min_version': '0.15',
         'required_at_installation': True,
         'install_info': _NILEARN_INSTALL_MSG}),
     ('nibabel', {


Test patch:
diff --git a/nilearn/_utils/testing.py b/nilearn/_utils/testing.py
--- a/nilearn/_utils/testing.py
+++ b/nilearn/_utils/testing.py
@@ -14,6 +14,7 @@
 import numpy as np
 import scipy.signal
 from sklearn.utils import check_random_state
+from sklearn.utils.testing import assert_warns
 import scipy.linalg
 import nibabel
 
@@ -29,16 +30,6 @@
     # For Py 2.7
     from nose.tools import assert_raises_regexp as assert_raises_regex
 
-try:
-    from sklearn.utils.testing import assert_warns
-except ImportError:
-    # sklearn.utils.testing.assert_warns new in scikit-learn 0.14
-    def assert_warns(warning_class, func, *args, **kw):
-        with warnings.catch_warnings(record=True):
-            warnings.simplefilter("ignore", warning_class)
-            output = func(*args, **kw)
-        return output
-
 
 # we use memory_profiler library for memory consumption checks
 try:
diff --git a/nilearn/input_data/tests/test_multi_nifti_masker.py b/nilearn/input_data/tests/test_multi_nifti_masker.py
--- a/nilearn/input_data/tests/test_multi_nifti_masker.py
+++ b/nilearn/input_data/tests/test_multi_nifti_masker.py
@@ -133,34 +133,32 @@ def test_joblib_cache():
 
 
 def test_shelving():
-    if LooseVersion(sklearn.__version__) >= LooseVersion('0.15'):
-        mask_img = Nifti1Image(np.ones((2, 2, 2), dtype=np.int8),
-                               affine=np.diag((4, 4, 4, 1)))
-        epi_img1 = Nifti1Image(np.ones((2, 2, 2)),
-                               affine=np.diag((4, 4, 4, 1)))
-        epi_img2 = Nifti1Image(np.ones((2, 2, 2)),
-                               affine=np.diag((2, 2, 2, 1)))
-        cachedir = mkdtemp()
-        try:
-            masker_shelved = MultiNiftiMasker(mask_img=mask_img,
-                                              memory=Memory(cachedir=cachedir,
-                                                            mmap_mode='r',
-                                                            verbose=0))
-            masker_shelved._shelving = True
-            masker = MultiNiftiMasker(mask_img=mask_img)
-            epis_shelved = masker_shelved.fit_transform([epi_img1, epi_img2])
-            epis = masker.fit_transform([epi_img1, epi_img2])
-            for epi_shelved, epi in zip(epis_shelved, epis):
-                epi_shelved = epi_shelved.get()
-                assert_array_equal(epi_shelved, epi)
-
-            epi = masker.fit_transform(epi_img1)
-            epi_shelved = masker_shelved.fit_transform(epi_img1)
+
+    mask_img = Nifti1Image(np.ones((2, 2, 2), dtype=np.int8),
+                           affine=np.diag((4, 4, 4, 1)))
+    epi_img1 = Nifti1Image(np.ones((2, 2, 2)),
+                           affine=np.diag((4, 4, 4, 1)))
+    epi_img2 = Nifti1Image(np.ones((2, 2, 2)),
+                           affine=np.diag((2, 2, 2, 1)))
+    cachedir = mkdtemp()
+    try:
+        masker_shelved = MultiNiftiMasker(mask_img=mask_img,
+                                          memory=Memory(cachedir=cachedir,
+                                                        mmap_mode='r',
+                                                        verbose=0))
+        masker_shelved._shelving = True
+        masker = MultiNiftiMasker(mask_img=mask_img)
+        epis_shelved = masker_shelved.fit_transform([epi_img1, epi_img2])
+        epis = masker.fit_transform([epi_img1, epi_img2])
+        for epi_shelved, epi in zip(epis_shelved, epis):
             epi_shelved = epi_shelved.get()
             assert_array_equal(epi_shelved, epi)
-        finally:
-            # enables to delete "filename" on windows
-            del masker
-            shutil.rmtree(cachedir, ignore_errors=True)
-    else:
-        pass
+
+        epi = masker.fit_transform(epi_img1)
+        epi_shelved = masker_shelved.fit_transform(epi_img1)
+        epi_shelved = epi_shelved.get()
+        assert_array_equal(epi_shelved, epi)
+    finally:
+        # enables to delete "filename" on windows
+        del masker
+        shutil.rmtree(cachedir, ignore_errors=True)
diff --git a/nilearn/tests/test_cache_mixin.py b/nilearn/tests/test_cache_mixin.py
--- a/nilearn/tests/test_cache_mixin.py
+++ b/nilearn/tests/test_cache_mixin.py
@@ -187,19 +187,12 @@ def test_cache_shelving():
         job_glob = os.path.join(temp_dir, 'joblib', 'nilearn', 'tests',
                                 'test_cache_mixin', 'f', '*')
         mem = Memory(cachedir=temp_dir, verbose=0)
-        if LooseVersion(sklearn.__version__) >= LooseVersion('0.15'):
-            res = cache_mixin.cache(f, mem, shelve=True)(2)
-            assert_equal(res.get(), 2)
-            assert_equal(len(glob.glob(job_glob)), 1)
-            res = cache_mixin.cache(f, mem, shelve=True)(2)
-            assert_equal(res.get(), 2)
-            assert_equal(len(glob.glob(job_glob)), 1)
-        else:
-            assert_raises_regex(ValueError, 'Shelving is only available'
-                                            ' if scikit-learn >= 0.15'
-                                            ' is installed.',
-                                cache_mixin.cache,
-                                f, mem, shelve=True)
+        res = cache_mixin.cache(f, mem, shelve=True)(2)
+        assert_equal(res.get(), 2)
+        assert_equal(len(glob.glob(job_glob)), 1)
+        res = cache_mixin.cache(f, mem, shelve=True)(2)
+        assert_equal(res.get(), 2)
+        assert_equal(len(glob.glob(job_glob)), 1)
     finally:
         del mem
         shutil.rmtree(temp_dir, ignore_errors=True)
diff --git a/nilearn/tests/test_testing.py b/nilearn/tests/test_testing.py
--- a/nilearn/tests/test_testing.py
+++ b/nilearn/tests/test_testing.py
@@ -15,8 +15,8 @@ def create_object(size):
 
 @with_memory_profiler
 def test_memory_usage():
-    # Valid measures
-    for mem in (500, 200, 100):
+    # Valid measures (larger objects)
+    for mem in (500, 200):
         assert_memory_less_than(mem, 0.1, create_object, mem * 1024 ** 2)
 
     # Ensure an exception is raised with too small objects as
@@ -30,8 +30,8 @@ def test_memory_usage():
     # limit.
     assert_raises_regex(ValueError,
                         "Memory consumption measured",
-                        assert_memory_less_than, 50, 0.1,
-                        create_object, 100 * 1024 ** 2)
+                        assert_memory_less_than, 100, 0.1,
+                        create_object, 200 * 1024 ** 2)
 
 
 def test_generate_fake_fmri():