internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: nilearn/nilearn

Issue:
plot_img should have colorbar as explicit argument
Mentioned in #379. You can pass 'colorbar' via kwargs into plot_img but you have to read the code to know that it is possible. Adding an explicit colorbar argument + docstring would make it a lot more obvious.

Probably worth to check that plot_img arguments are a superset of the other plot_\* functions arguments.



Discussion:

Resolving patch:
diff --git a/nilearn/plotting/img_plotting.py b/nilearn/plotting/img_plotting.py
--- a/nilearn/plotting/img_plotting.py
+++ b/nilearn/plotting/img_plotting.py
@@ -112,7 +112,7 @@ def _plot_img_with_bg(img, bg_img=None, cut_coords=None,
 
 def plot_img(img, cut_coords=None, output_file=None, display_mode='ortho',
             figure=None, axes=None, title=None, threshold=None,
-            annotate=True, draw_cross=True, black_bg=False, **kwargs):
+            annotate=True, draw_cross=True, black_bg=False, colorbar=False, **kwargs):
     """ Plot cuts of a given image (by default Frontal, Axial, and Lateral)
 
         Parameters
@@ -162,6 +162,8 @@ def plot_img(img, cut_coords=None, output_file=None, display_mode='ortho',
             you wish to save figures with a black background, you
             will need to pass "facecolor='k', edgecolor='k'" to pylab's
             savefig.
+        colorbar: boolean, optional
+            If True, display a colorbar on the right of the plots.
         kwargs: extra keyword arguments, optional
             Extra keyword arguments passed to pylab.imshow
     """
@@ -170,7 +172,7 @@ def plot_img(img, cut_coords=None, output_file=None, display_mode='ortho',
                     figure=figure, axes=axes, title=title,
                     threshold=threshold, annotate=annotate,
                     draw_cross=draw_cross,
-                    black_bg=black_bg, **kwargs)
+                    black_bg=black_bg, colorbar=colorbar, **kwargs)
 
     return display
 


Test patch:
Repository: nilearn/nilearn

Issue:
Ugly side plots in doc
They mask part of the code they are supposed to illustrate. See an example [here](http://nilearn.github.io/building_blocks/data_preparation.html#computing-the-mask).

![ugly-side-plots](https://cloud.githubusercontent.com/assets/1680079/5974579/266c30d8-a876-11e4-8830-febff99ed1dc.png)



Discussion:
I am working on this.


Resolving patch:
diff --git a/examples/connectivity/plot_adhd_covariance.py b/examples/connectivity/plot_adhd_covariance.py
--- a/examples/connectivity/plot_adhd_covariance.py
+++ b/examples/connectivity/plot_adhd_covariance.py
@@ -20,13 +20,11 @@
 def plot_matrices(cov, prec, title):
     """Plot covariance and precision matrices, for a given processing. """
 
+    # Compute sparsity pattern
+    sparsity = (prec == 0)
+    
     prec = prec.copy()  # avoid side effects
 
-    # Display sparsity pattern
-    sparsity = prec == 0
-    plt.figure()
-    plt.imshow(sparsity, interpolation="nearest")
-    plt.title("%s / sparsity" % title)
 
     # Put zeros on the diagonal, for graph clarity.
     size = prec.shape[0]
@@ -39,6 +37,11 @@ def plot_matrices(cov, prec, title):
               vmin=-1, vmax=1, cmap=plt.cm.get_cmap("bwr"))
     plt.colorbar()
     plt.title("%s / covariance" % title)
+    
+    # Display sparsity pattern
+    plt.figure()
+    plt.imshow(sparsity, interpolation="nearest")
+    plt.title("%s / sparsity" % title)
 
     # Display precision matrix
     plt.figure()


Test patch:
Repository: nilearn/nilearn

Issue:
Please clarify copyrights
INRIA or nilearn developers?

```
$> git grep -i Copyright doc/conf.py COPYING 
COPYING:Copyright (c) 2007 - 2013 The nilearn developers.
doc/conf.py:copyright = u'INRIA Parietal 2010-2013'
```

you might also like to symlink COPYING into doc/ to avoid diverging them:

```
$> diff COPYING doc/COPYING
3c3
< Copyright (c) 2007 - 2013 The nilearn developers.

---
> Copyright (c) 2009 - 2013 nilearn developers.
15c15
<   c. Neither the name of the nilearn Developers nor the names of

---
>   c. Neither the name of the nilearn Developers  nor the names of
```

and would be neat if at least briefly copyright/licenses of used/shipped 3rd party modules were mentioned in COPYING:

```
doc/sphinxext/LICENSE.txt:Copyright (C) 2008 Stefan van der Walt <stefan@mentat.za.net>, Pauli Virtanen <pav@iki.fi>
doc/sphinxext/LICENSE.txt:Copyright (c) 2006, Enthought, Inc.
doc/sphinxext/LICENSE.txt:Copyright (c) 2002-2008 John D. Hunter; All Rights Reserved.
doc/themes/nilearn/static/jquery.jcarousel.min.js:* Copyright (c) 2014 Jan Sorgalla; Licensed MIT */
doc/themes/nilearn/static/sphinxdoc.css: * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
```



Discussion:
Good catch! I am probably not the best person for this kind of issues but I am convinced we can do something about it and tidy up the copyrights.

Indeed,  we should put nilearn developers. Some of them are employed by inria but not all.

Sent from my phone. Please forgive brevity and mis spelling

On Feb 6, 2015, 18:53, at 18:53, "Loïc Estève" notifications@github.com wrote:

> Good catch! I am probably not the best person for this kind of issues
> but I am convinced we can do something about it and tidy up the
> copyrights.
> 
> ---
> 
> Reply to this email directly or view it on GitHub:
> https://github.com/nilearn/nilearn/issues/415#issuecomment-73281910


Resolving patch:
diff --git a/doc/conf.py b/doc/conf.py
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -77,7 +77,7 @@
 
 # General information about the project.
 project = u'Nilearn'
-copyright = u'INRIA Parietal 2010-2013'
+copyright = u'The nilearn developers 2010-2015'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the


Test patch:
Repository: nilearn/nilearn

Issue:
Check_fitted() appears to be missing for some members of the (mystical) masker family



Discussion:

Resolving patch:
diff --git a/nilearn/input_data/base_masker.py b/nilearn/input_data/base_masker.py
--- a/nilearn/input_data/base_masker.py
+++ b/nilearn/input_data/base_masker.py
@@ -289,3 +289,9 @@ def inverse_transform(self, X):
         except:
             pass
         return img
+
+    def _check_fitted(self):
+        if not hasattr(self, "mask_img_"):
+            raise ValueError('It seems that %s has not been fitted. '
+                             'You must call fit() before calling transform().'
+                             % self.__class__.__name__)
diff --git a/nilearn/input_data/multi_nifti_masker.py b/nilearn/input_data/multi_nifti_masker.py
--- a/nilearn/input_data/multi_nifti_masker.py
+++ b/nilearn/input_data/multi_nifti_masker.py
@@ -237,6 +237,8 @@ def transform(self, imgs, confounds=None):
         data: {list of numpy arrays}
             preprocessed images
         """
+        self._check_fitted()
+
         if not hasattr(imgs, '__iter__')\
                     or isinstance(imgs, string_types):
                 return self.transform_single_imgs(imgs)
diff --git a/nilearn/input_data/nifti_masker.py b/nilearn/input_data/nifti_masker.py
--- a/nilearn/input_data/nifti_masker.py
+++ b/nilearn/input_data/nifti_masker.py
@@ -216,5 +216,7 @@ def transform(self, imgs, confounds=None):
             This parameter is passed to nilearn.signal.clean. Please see the
             related documentation for details
         """
+        self._check_fitted()
+
         return self.transform_single_imgs(
             imgs, confounds, sample_mask=self.sample_mask)


Test patch:
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
@@ -44,6 +44,12 @@ def test_auto_mask():
     # It should also work with a 3D image
     masker.transform(img)
 
+    # check exception when transform() called without prior fit()
+    masker2 = MultiNiftiMasker(mask_img=img)
+    assert_raises_regex(
+        ValueError,
+        'has not been fitted. ', masker2.transform, img2)
+
 
 def test_nan():
     data = np.ones((9, 9, 9))
diff --git a/nilearn/input_data/tests/test_nifti_masker.py b/nilearn/input_data/tests/test_nifti_masker.py
--- a/nilearn/input_data/tests/test_nifti_masker.py
+++ b/nilearn/input_data/tests/test_nifti_masker.py
@@ -42,6 +42,12 @@ def test_auto_mask():
     # With a 3D img
     masker.transform(img)
 
+    # check exception when transform() called without prior fit()
+    masker2 = NiftiMasker(mask_img=img)
+    testing.assert_raises_regex(
+        ValueError,
+        'has not been fitted. ', masker2.transform, img)
+
 
 def test_with_files():
     # Standard masking
Repository: nilearn/nilearn

Issue:
Nilearn is not compatible with six 1.5.2 (361 day old version)
I think we should support this version. The problem is located in some display in the dataset fetcher:

`displayed_url = urllib.parse.splitquery(url)[0] if verbose == 1 else url`

A solution would be to replace `splitquery` by `url.split('?')[0]`.



Discussion:

Resolving patch:
diff --git a/nilearn/datasets.py b/nilearn/datasets.py
--- a/nilearn/datasets.py
+++ b/nilearn/datasets.py
@@ -475,7 +475,7 @@ def _fetch_file(url, data_dir, resume=True, overwrite=False,
                 'Authorization',
                 b'Basic ' + base64.b64encode(username + b':' + password))
         if verbose > 0:
-            displayed_url = urllib.parse.splitquery(url)[0] if verbose == 1 else url
+            displayed_url = url.split('?')[0] if verbose == 1 else url
             print('Downloading data from %s ...' % displayed_url)
         if resume and os.path.exists(temp_full_name):
             url_opener = ResumeURLOpener()


Test patch:
Repository: nilearn/nilearn

Issue:
Add test for compatibility of old version of six
For the moment, we are compatible with the latest version of six. Recently, somebody pointed out that we did not support six 1.5.2. We should investigate, decide which version we should be compatible with and then add this to Travis.



Discussion:

Resolving patch:
diff --git a/continuous_integration/show-python-packages-versions.py b/continuous_integration/show-python-packages-versions.py
--- a/continuous_integration/show-python-packages-versions.py
+++ b/continuous_integration/show-python-packages-versions.py
@@ -1,6 +1,6 @@
 import sys
 
-DEPENDENCIES = ['numpy', 'scipy', 'sklearn', 'matplotlib', 'nibabel']
+DEPENDENCIES = ['six', 'numpy', 'scipy', 'sklearn', 'matplotlib', 'nibabel']
 
 
 def print_package_version(package_name, indent='  '):


Test patch:
Repository: nilearn/nilearn

Issue:
nilearn.datasets.fetch_abide_pcp() is failing on my machine
Error traceback is:

``` python

from nilearn import datasets
stuff = datasets.fetch_abide_pcp()
```

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-391feae800c5> in <module>()
----> 1 stuff = fetch_abide_pcp(n_subjects=1)

/git/nilearn/nilearn/datasets.py in fetch_abide_pcp(data_dir, n_subjects, pipeline, band_pass_filtering, global_signal_regression, derivatives, quality_checked, url, verbose, **kwargs)
   2565     # We enforce a magic string  forcomments because it is 'sharp' by default,
   2566     #   and Python 3.4 doesn't like empty
-> 2567     pheno = np.recfromcsv(pheno, comments='__magic_string__', case_sensitive=True)
   2568 
   2569     # First, filter subjects with no filename

/Users/admin/anaconda/lib/python2.7/site-packages/numpy/lib/npyio.pyc in recfromcsv(fname, **kwargs)
   1908     kwargs.setdefault("delimiter", ",")
   1909     kwargs.setdefault("dtype", None)
-> 1910     output = genfromtxt(fname, **kwargs)
   1911 
   1912     usemask = kwargs.get("usemask", False)

/Users/admin/anaconda/lib/python2.7/site-packages/numpy/lib/npyio.pyc in genfromtxt(fname, dtype, comments, delimiter, skiprows, skip_header, skip_footer, converters, missing, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise)
   1690             # Raise an exception ?
   1691             if invalid_raise:
-> 1692                 raise ValueError(errmsg)
   1693             # Issue a warning ?
   1694             else:

ValueError: Some errors were detected !
    Line #3 (got 106 columns instead of 105)
```



Discussion:
Fails for me too. I seem to remember @AlexandreAbraham has fixed similar issues for other datasets a little while ago, maybe if you looked in the git history you'll get some hints on how to fix it.


Resolving patch:
diff --git a/nilearn/datasets.py b/nilearn/datasets.py
--- a/nilearn/datasets.py
+++ b/nilearn/datasets.py
@@ -2568,7 +2568,7 @@ def fetch_abide_pcp(data_dir=None, n_subjects=None, pipeline='cpac',
     pheno = BytesIO(pheno)
     # We enforce a magic string  forcomments because it is 'sharp' by default,
     #   and Python 3.4 doesn't like empty
-    pheno = np.recfromcsv(pheno, comments='__magic_string__', case_sensitive=True)
+    pheno = np.recfromcsv(pheno, comments='$', case_sensitive=True)
 
     # First, filter subjects with no filename
     pheno = pheno[pheno['FILE_ID'] != b'no_filename']


Test patch:
Repository: nilearn/nilearn

Issue:
Doc does not build
Am I the only one?

```
Exception occurred:
  File "/home/aa013911/work/nilearn/doc/sphinxext/sphinxgallery/docs_resolv.py", line 348, in embed_code_links
    gallery_dir = os.path.join(app.builder.srcdir, gallery_conf['gallery_dir'])
KeyError: 'gallery_dir'
The full traceback has been saved in /tmp/sphinx-err-sePU7r.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
```



Discussion:
Just launched a clean doc generation from master, will let you know.

Does your error happens after or before the examples are run ?

I've done a noplot, so no build of examples.

I get the same error with `cd doc && make html-noplot`

Looks like this is a bug related to noplot, app.config.sphinxgallery_conf is not properly updated when plot_gallery is False.

@Titan-C, I think the only thing is to move the `if not plot_gallery: return` after this [line](https://github.com/sphinx-gallery/sphinx-gallery/blob/master/sphinxgallery/gen_gallery.py#L25)

I get the same problem. We need to address this fast: currently master is somewhat broken.

This has been fixed in sphinx-gallery master [here](https://github.com/sphinx-gallery/sphinx-gallery/commit/6e944e29e8b23a85025b6bf44ebb6d39907d1875). 

I was thinking we could have a 0.9 sphinx-gallery release to fix this.

cc @Titan-C.

Is it doable fast enough? Because I am not against a quickfix in our copy of sphinx in the meantime.


Resolving patch:
diff --git a/doc/sphinxext/sphinxgallery/__init__.py b/doc/sphinxext/sphinxgallery/__init__.py
--- a/doc/sphinxext/sphinxgallery/__init__.py
+++ b/doc/sphinxext/sphinxgallery/__init__.py
@@ -1,7 +1,7 @@
 """Sphinx Gallery
 """
 import os
-__version__ = '0.0.8'
+__version__ = '0.0.9-dev'
 
 def path_static():
     """Returns path to packaged static files"""
diff --git a/doc/sphinxext/sphinxgallery/gen_gallery.py b/doc/sphinxext/sphinxgallery/gen_gallery.py
--- a/doc/sphinxext/sphinxgallery/gen_gallery.py
+++ b/doc/sphinxext/sphinxgallery/gen_gallery.py
@@ -16,14 +16,14 @@ def generate_gallery_rst(app):
     except TypeError:
         plot_gallery = bool(app.builder.config.plot_gallery)
 
-    if not plot_gallery:
-        return
-
     gallery_conf.update(app.config.sphinxgallery_conf)
 
     # this assures I can call the config in other places
     app.config.sphinxgallery_conf = gallery_conf
 
+    if not plot_gallery:
+        return
+
     examples_dir = os.path.join(app.builder.srcdir, gallery_conf['examples_dir'])
     gallery_dir = os.path.join(app.builder.srcdir, gallery_conf['gallery_dir'])
     mod_examples_dir = os.path.join(app.builder.srcdir, gallery_conf['mod_example_dir'])


Test patch:
Repository: nilearn/nilearn

Issue:
image.index_img fails with single element list input
dataset object e.g. haxby_dataset["func"] returns a single element list and image.index_img(hb_dataset["func"]) fails with single element list input



Discussion:
`index_img` is meant to iterate over one image, not a list of image. `image.index_img(hb.func[0], 0) will work. What do you want to do exactly?

> index_img is meant to iterate over one image, not a list of image.
> `image.index_img(hb.func[0], 0) will work. What do you want to do exactly?

I don't think that we dispute that there is a user error. The point is
rather that the error message is quite useless.

In fact there is no check of the dimensionality of the first image! I'll do a quickfix.


Resolving patch:
diff --git a/nilearn/_utils/niimg_conversions.py b/nilearn/_utils/niimg_conversions.py
--- a/nilearn/_utils/niimg_conversions.py
+++ b/nilearn/_utils/niimg_conversions.py
@@ -285,19 +285,24 @@ def concat_niimgs(niimgs, dtype=np.float32, ensure_ndim=None,
 
     target_fov = 'first' if auto_resample else None
 
+    # We remove one to the dimensionality because of the list is one dimension.
+    ndim = None
+    if ensure_ndim is not None:
+        ndim = ensure_ndim - 1
+
     # First niimg is extracted to get information and for new_img_like
     first_niimg = None
 
     iterator, literator = itertools.tee(iter(niimgs))
     try:
-        first_niimg = check_niimg(next(literator))
+        first_niimg = check_niimg(next(literator), ensure_ndim=ndim)
     except StopIteration:
         raise TypeError('Cannot concatenate empty objects')
 
-    if ensure_ndim is None:
+    # If no particular dimensionality is asked, we force consistency wrt the
+    # first image
+    if ndim is None:
         ndim = len(first_niimg.shape)
-    else:
-        ndim = ensure_ndim - 1
 
     lengths = [first_niimg.shape[-1] if ndim == 4 else 1]
     for niimg in literator:


Test patch:
diff --git a/nilearn/tests/test_niimg_conversions.py b/nilearn/tests/test_niimg_conversions.py
--- a/nilearn/tests/test_niimg_conversions.py
+++ b/nilearn/tests/test_niimg_conversions.py
@@ -169,6 +169,12 @@ def test_concat_niimgs():
     shape3 = (11, 22, 33)
     img1c = Nifti1Image(np.ones(shape3), affine)
 
+    # Regression test for #601. Dimensionality of first image was not checked
+    # properly
+    assert_raises_regex(TypeError, 'Data must be a 3D Niimg-like object but '
+                        'you provided an image of shape',
+                        _utils.concat_niimgs, [img4d], ensure_ndim=4)
+
     # check basic concatenation with equal shape/affine
     concatenated = _utils.concat_niimgs((img1, img3, img1))
Repository: nilearn/nilearn

Issue:
Basic authentication header should only be sent using HTTPS
Basic authentication exposes username/password as unencrypted (base64 encoded, which has no encryption). Because of this, it is only appropriate to send over secure connections (HTTPS).

In the current code, I don't believe there is any such check:
 https://github.com/nilearn/nilearn/blob/b89a84aa9790651c27e02c738623c8086b637589/nilearn/datasets.py#L498

I suggest making that check :)



Discussion:
Sounds good to me!

Gaël

You are totally right.


Resolving patch:
diff --git a/nilearn/datasets/utils.py b/nilearn/datasets/utils.py
--- a/nilearn/datasets/utils.py
+++ b/nilearn/datasets/utils.py
@@ -480,6 +480,10 @@ def _fetch_file(url, data_dir, resume=True, overwrite=False,
         request = _urllib.request.Request(url)
         request.add_header('Connection', 'Keep-Alive')
         if username is not None and password is not None:
+            if not url.startswith('https'):
+                raise ValueError(
+                    'Authentication was requested on a non  secured URL (%s).'
+                    'Request has been blocked for security reasons.' % url)
             # Note: HTTPBasicAuthHandler is not fitted here because it relies
             # on the fact that the server will return a 401 error with proper
             # www-authentication header, which is not the case of most


Test patch:
Repository: nilearn/nilearn

Issue:
Improve task mask pattern in examples
``` python
classification_target = stimuli[
    np.logical_not(resting_state)] == category
```

From #740, @AlexandreAbraham  said:

> I already found this line hard to understand before (I particularly dislike playing with the priority of operators = and ==) but now the new_line make it even more obscure. Maybe we could change by:
> 
> ```
> task_mask = np.logical_not(resting_state)  # or sample_mask?
> classification_target = (stimuli[task_mask] == category)
> ```

Quickly git-grepping it looks like this pattern is both present in:
examples/decoding/plot_haxby_different_estimators.py
examples/decoding/plot_haxby_full_analysis.py

They may be other places where this is used.



Discussion:
Maybe one for @KamalakerDadi if you want an easy one to take your mind off  your bigger AutoExtractor PR.

Please assign it. I will do it.


Resolving patch:
diff --git a/examples/decoding/plot_haxby_different_estimators.py b/examples/decoding/plot_haxby_different_estimators.py
--- a/examples/decoding/plot_haxby_different_estimators.py
+++ b/examples/decoding/plot_haxby_different_estimators.py
@@ -95,8 +95,8 @@
     print(70 * '_')
 
     for category in categories:
-        classification_target = stimuli[
-            np.logical_not(resting_state)] == category
+        task_mask = np.logical_not(resting_state)
+        classification_target = (stimuli[task_mask] == category)
         t0 = time.time()
         classifiers_scores[classifier_name][category] = cross_val_score(
             classifier,
diff --git a/examples/decoding/plot_haxby_full_analysis.py b/examples/decoding/plot_haxby_full_analysis.py
--- a/examples/decoding/plot_haxby_full_analysis.py
+++ b/examples/decoding/plot_haxby_full_analysis.py
@@ -72,8 +72,8 @@
 
     for category in categories:
         print("Processing %s %s" % (mask_name, category))
-        classification_target = stimuli[
-            np.logical_not(resting_state)] == category
+        task_mask = np.logical_not(resting_state)
+        classification_target = (stimuli[task_mask] == category)
         mask_scores[mask_name][category] = cross_val_score(
             classifier,
             masked_timecourses,


Test patch:
Repository: nilearn/nilearn

Issue:
`concat_niimgs` only handles 3D/4D but does not raise error if data is >4D
And actually, it squashes the last dimensions, which is pretty bad.



Discussion:

Resolving patch:
diff --git a/nilearn/_utils/niimg_conversions.py b/nilearn/_utils/niimg_conversions.py
--- a/nilearn/_utils/niimg_conversions.py
+++ b/nilearn/_utils/niimg_conversions.py
@@ -363,6 +363,10 @@ def concat_niimgs(niimgs, dtype=np.float32, ensure_ndim=None,
     if ndim is None:
         ndim = len(first_niimg.shape)
 
+    if ndim not in [3, 4]:
+        raise TypeError('Concatenated images must be 3D or 4D. You gave a '
+                        'list of %dD images' % ndim)
+
     lengths = [first_niimg.shape[-1] if ndim == 4 else 1]
     for niimg in literator:
         # We check the dimensionality of the niimg


Test patch:
diff --git a/nilearn/tests/test_niimg_conversions.py b/nilearn/tests/test_niimg_conversions.py
--- a/nilearn/tests/test_niimg_conversions.py
+++ b/nilearn/tests/test_niimg_conversions.py
@@ -269,6 +269,11 @@ def test_concat_niimgs():
         _remove_if_exists(tmpimg1)
         _remove_if_exists(tmpimg2)
 
+    img5d = Nifti1Image(np.ones((2, 2, 2, 2, 2)), affine)
+    assert_raises_regex(TypeError, 'Concatenated images must be 3D or 4D. '
+                        'You gave a list of 5D images', _utils.concat_niimgs,
+                        [img5d, img5d])
+
 
 def nifti_generator(buffer):
     for i in range(10):