prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  check_embedded_nifti_masker assumes estimator has attributes set
  **Disclaimer:** I know `check_embedded_nifti_masker` is implicitly meant to be a low-level function, etc., etc.
  
  ```
  Traceback (most recent call last):
    File "toto.py", line 13, in <module>
      Toto(memory=None).fit()
    File "toto.py", line 10, in fit
      self.masker_ = check_embedded_nifti_masker(self)
    File "/home/elvis/.local/lib/python2.7/site-packages/nilearn-0.2.3-py2.7.egg/nilearn/input_data/masker_validation.py", line 53, in check_embedded_nifti_masker
      new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)
  AttributeError: 'Toto' object has no attribute 'memory_level'
  ```
  
  Reproduce with:
  
  ```
  from nilearn.input_data.masker_validation import check_embedded_nifti_masker
  
  
  class Toto(object):
      def __init__(self, **kwargs):
          for k, v in kwargs.items():
              setattr(self, k, v)
  
      def fit(self, *args, **kwargs):
          self.masker_ = check_embedded_nifti_masker(self)
  
  
  Toto(memory=None).fit()
  ```
  
  check_embedded_nifti_masker assumes estimator has attributes set
  **Disclaimer:** I know `check_embedded_nifti_masker` is implicitly meant to be a low-level function, etc., etc.
  
  ```
  Traceback (most recent call last):
    File "toto.py", line 13, in <module>
      Toto(memory=None).fit()
    File "toto.py", line 10, in fit
      self.masker_ = check_embedded_nifti_masker(self)
    File "/home/elvis/.local/lib/python2.7/site-packages/nilearn-0.2.3-py2.7.egg/nilearn/input_data/masker_validation.py", line 53, in check_embedded_nifti_masker
      new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)
  AttributeError: 'Toto' object has no attribute 'memory_level'
  ```
  
  Reproduce with:
  
  ```
  from nilearn.input_data.masker_validation import check_embedded_nifti_masker
  
  
  class Toto(object):
      def __init__(self, **kwargs):
          for k, v in kwargs.items():
              setattr(self, k, v)
  
      def fit(self, *args, **kwargs):
          self.masker_ = check_embedded_nifti_masker(self)
  
  
  Toto(memory=None).fit()
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `nilearn/input_data/masker_validation.py`
  Content:
  ```
  1 import warnings
  2 
  3 import numpy as np
  4 
  5 from .._utils.class_inspect import get_params
  6 from .._utils.cache_mixin import _check_memory
  7 from .multi_nifti_masker import MultiNiftiMasker
  8 from .nifti_masker import NiftiMasker
  9 
  10 
  11 def check_embedded_nifti_masker(estimator, multi_subject=True):
  12     """Base function for using a masker within a BaseEstimator class
  13 
  14     This creates a masker from instance parameters :
  15     - If instance contains a mask image in mask parameter,
  16     we use this image as new masker mask_img, forwarding instance parameters to
  17     new masker : smoothing_fwhm, standardize, detrend, low_pass= high_pass,
  18     t_r, target_affine, target_shape, mask_strategy, mask_args,
  19     - If instance contains a masker in mask parameter, we use a copy of
  20     this masker, overriding all instance masker related parameters.
  21     In all case, we forward system parameters of instance to new masker :
  22     memory, memory_level, verbose, n_jobs
  23 
  24     Parameters
  25     ----------
  26     instance: object, instance of BaseEstimator
  27         The object that gives us the values of the parameters
  28 
  29     multi_subject: boolean
  30         Indicates whether to return a MultiNiftiMasker or a NiftiMasker
  31         (the default is True)
  32 
  33     Returns
  34     -------
  35     masker: MultiNiftiMasker or NiftiMasker
  36         New masker
  37     """
  38     masker_type = MultiNiftiMasker if multi_subject else NiftiMasker
  39     estimator_params = get_params(masker_type, estimator)
  40     mask = getattr(estimator, 'mask', None)
  41 
  42     if isinstance(mask, (NiftiMasker, MultiNiftiMasker)):
  43         # Creating (Multi)NiftiMasker from provided masker
  44         masker_params = get_params(masker_type, mask)
  45         new_masker_params = masker_params
  46     else:
  47         # Creating (Multi)NiftiMasker
  48         # with parameters extracted from estimator
  49         new_masker_params = estimator_params
  50         new_masker_params['mask_img'] = mask
  51     # Forwarding system parameters of instance to new masker in all case
  52     if multi_subject and hasattr(estimator, 'n_jobs'):
  53         # For MultiNiftiMasker only
  54         new_masker_params['n_jobs'] = estimator.n_jobs
  55     new_masker_params['memory'] = _check_memory(estimator.memory)
  56     new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)
  57     new_masker_params['verbose'] = estimator.verbose
  58 
  59     # Raising warning if masker override parameters
  60     conflict_string = ""
  61     for param_key in sorted(estimator_params):
  62         if np.any(new_masker_params[param_key] != estimator_params[param_key]):
  63             conflict_string += ("Parameter {0} :\n"
  64                                 "    Masker parameter {1}"
  65                                 " - overriding estimator parameter {2}\n"
  66                                 ).format(param_key,
  67                                          new_masker_params[param_key],
  68                                          estimator_params[param_key])
  69 
  70     if conflict_string != "":
  71         warn_str = ("Overriding provided-default estimator parameters with"
  72                     " provided masker parameters :\n"
  73                     "{0:s}").format(conflict_string)
  74         warnings.warn(warn_str)
  75     masker = masker_type(**new_masker_params)
  76 
  77     # Forwarding potential attribute of provided masker
  78     if hasattr(mask, 'mask_img_'):
  79         # Allow free fit of returned mask
  80         masker.mask_img = mask.mask_img_
  81 
  82     return masker
  83
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/nilearn/input_data/masker_validation.py b/nilearn/input_data/masker_validation.py
  --- a/nilearn/input_data/masker_validation.py
  +++ b/nilearn/input_data/masker_validation.py
  @@ -1,6 +1,7 @@
   import warnings
   
   import numpy as np
  +from string import Template
   
   from .._utils.class_inspect import get_params
   from .._utils.cache_mixin import _check_memory
  @@ -52,9 +53,30 @@
       if multi_subject and hasattr(estimator, 'n_jobs'):
           # For MultiNiftiMasker only
           new_masker_params['n_jobs'] = estimator.n_jobs
  -    new_masker_params['memory'] = _check_memory(estimator.memory)
  -    new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)
  -    new_masker_params['verbose'] = estimator.verbose
  +
  +    warning_msg = Template("Provided estimator has no $attribute attribute set."
  +                           "Setting $attribute to $default_value by default.")
  +
  +    if hasattr(estimator, 'memory'):
  +        new_masker_params['memory'] = _check_memory(estimator.memory)
  +    else:
  +        warnings.warn(warning_msg.substitute(attribute='memory',
  +                                             default_value='Memory(location=None)'))
  +        new_masker_params['memory'] = _check_memory(None)
  +
  +    if hasattr(estimator, 'memory_level'):
  +        new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)
  +    else:
  +        warnings.warn(warning_msg.substitute(attribute='memory_level',
  +                                             default_value='0'))
  +        new_masker_params['memory_level'] = 0
  +
  +    if hasattr(estimator, 'verbose'):
  +        new_masker_params['verbose'] = estimator.verbose
  +    else:
  +        warnings.warn(warning_msg.substitute(attribute='verbose',
  +                                             default_value='0'))
  +        new_masker_params['verbose'] = 0
   
       # Raising warning if masker override parameters
       conflict_string = ""
  
verification_info: {"golden_diff": "diff --git a/nilearn/input_data/masker_validation.py b/nilearn/input_data/masker_validation.py\n--- a/nilearn/input_data/masker_validation.py\n+++ b/nilearn/input_data/masker_validation.py\n@@ -1,6 +1,7 @@\n import warnings\n \n import numpy as np\n+from string import Template\n \n from .._utils.class_inspect import get_params\n from .._utils.cache_mixin import _check_memory\n@@ -52,9 +53,30 @@\n     if multi_subject and hasattr(estimator, 'n_jobs'):\n         # For MultiNiftiMasker only\n         new_masker_params['n_jobs'] = estimator.n_jobs\n-    new_masker_params['memory'] = _check_memory(estimator.memory)\n-    new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)\n-    new_masker_params['verbose'] = estimator.verbose\n+\n+    warning_msg = Template(\"Provided estimator has no $attribute attribute set.\"\n+                           \"Setting $attribute to $default_value by default.\")\n+\n+    if hasattr(estimator, 'memory'):\n+        new_masker_params['memory'] = _check_memory(estimator.memory)\n+    else:\n+        warnings.warn(warning_msg.substitute(attribute='memory',\n+                                             default_value='Memory(location=None)'))\n+        new_masker_params['memory'] = _check_memory(None)\n+\n+    if hasattr(estimator, 'memory_level'):\n+        new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)\n+    else:\n+        warnings.warn(warning_msg.substitute(attribute='memory_level',\n+                                             default_value='0'))\n+        new_masker_params['memory_level'] = 0\n+\n+    if hasattr(estimator, 'verbose'):\n+        new_masker_params['verbose'] = estimator.verbose\n+    else:\n+        warnings.warn(warning_msg.substitute(attribute='verbose',\n+                                             default_value='0'))\n+        new_masker_params['verbose'] = 0\n \n     # Raising warning if masker override parameters\n     conflict_string = \"\"\n", "issue": "check_embedded_nifti_masker assumes estimator has attributes set\n**Disclaimer:** I know `check_embedded_nifti_masker` is implicitly meant to be a low-level function, etc., etc.\n\n```\nTraceback (most recent call last):\n  File \"toto.py\", line 13, in <module>\n    Toto(memory=None).fit()\n  File \"toto.py\", line 10, in fit\n    self.masker_ = check_embedded_nifti_masker(self)\n  File \"/home/elvis/.local/lib/python2.7/site-packages/nilearn-0.2.3-py2.7.egg/nilearn/input_data/masker_validation.py\", line 53, in check_embedded_nifti_masker\n    new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)\nAttributeError: 'Toto' object has no attribute 'memory_level'\n```\n\nReproduce with:\n\n```\nfrom nilearn.input_data.masker_validation import check_embedded_nifti_masker\n\n\nclass Toto(object):\n    def __init__(self, **kwargs):\n        for k, v in kwargs.items():\n            setattr(self, k, v)\n\n    def fit(self, *args, **kwargs):\n        self.masker_ = check_embedded_nifti_masker(self)\n\n\nToto(memory=None).fit()\n```\n\ncheck_embedded_nifti_masker assumes estimator has attributes set\n**Disclaimer:** I know `check_embedded_nifti_masker` is implicitly meant to be a low-level function, etc., etc.\n\n```\nTraceback (most recent call last):\n  File \"toto.py\", line 13, in <module>\n    Toto(memory=None).fit()\n  File \"toto.py\", line 10, in fit\n    self.masker_ = check_embedded_nifti_masker(self)\n  File \"/home/elvis/.local/lib/python2.7/site-packages/nilearn-0.2.3-py2.7.egg/nilearn/input_data/masker_validation.py\", line 53, in check_embedded_nifti_masker\n    new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)\nAttributeError: 'Toto' object has no attribute 'memory_level'\n```\n\nReproduce with:\n\n```\nfrom nilearn.input_data.masker_validation import check_embedded_nifti_masker\n\n\nclass Toto(object):\n    def __init__(self, **kwargs):\n        for k, v in kwargs.items():\n            setattr(self, k, v)\n\n    def fit(self, *args, **kwargs):\n        self.masker_ = check_embedded_nifti_masker(self)\n\n\nToto(memory=None).fit()\n```\n\n", "before_files": [{"content": "import warnings\n\nimport numpy as np\n\nfrom .._utils.class_inspect import get_params\nfrom .._utils.cache_mixin import _check_memory\nfrom .multi_nifti_masker import MultiNiftiMasker\nfrom .nifti_masker import NiftiMasker\n\n\ndef check_embedded_nifti_masker(estimator, multi_subject=True):\n    \"\"\"Base function for using a masker within a BaseEstimator class\n\n    This creates a masker from instance parameters :\n    - If instance contains a mask image in mask parameter,\n    we use this image as new masker mask_img, forwarding instance parameters to\n    new masker : smoothing_fwhm, standardize, detrend, low_pass= high_pass,\n    t_r, target_affine, target_shape, mask_strategy, mask_args,\n    - If instance contains a masker in mask parameter, we use a copy of\n    this masker, overriding all instance masker related parameters.\n    In all case, we forward system parameters of instance to new masker :\n    memory, memory_level, verbose, n_jobs\n\n    Parameters\n    ----------\n    instance: object, instance of BaseEstimator\n        The object that gives us the values of the parameters\n\n    multi_subject: boolean\n        Indicates whether to return a MultiNiftiMasker or a NiftiMasker\n        (the default is True)\n\n    Returns\n    -------\n    masker: MultiNiftiMasker or NiftiMasker\n        New masker\n    \"\"\"\n    masker_type = MultiNiftiMasker if multi_subject else NiftiMasker\n    estimator_params = get_params(masker_type, estimator)\n    mask = getattr(estimator, 'mask', None)\n\n    if isinstance(mask, (NiftiMasker, MultiNiftiMasker)):\n        # Creating (Multi)NiftiMasker from provided masker\n        masker_params = get_params(masker_type, mask)\n        new_masker_params = masker_params\n    else:\n        # Creating (Multi)NiftiMasker\n        # with parameters extracted from estimator\n        new_masker_params = estimator_params\n        new_masker_params['mask_img'] = mask\n    # Forwarding system parameters of instance to new masker in all case\n    if multi_subject and hasattr(estimator, 'n_jobs'):\n        # For MultiNiftiMasker only\n        new_masker_params['n_jobs'] = estimator.n_jobs\n    new_masker_params['memory'] = _check_memory(estimator.memory)\n    new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)\n    new_masker_params['verbose'] = estimator.verbose\n\n    # Raising warning if masker override parameters\n    conflict_string = \"\"\n    for param_key in sorted(estimator_params):\n        if np.any(new_masker_params[param_key] != estimator_params[param_key]):\n            conflict_string += (\"Parameter {0} :\\n\"\n                                \"    Masker parameter {1}\"\n                                \" - overriding estimator parameter {2}\\n\"\n                                ).format(param_key,\n                                         new_masker_params[param_key],\n                                         estimator_params[param_key])\n\n    if conflict_string != \"\":\n        warn_str = (\"Overriding provided-default estimator parameters with\"\n                    \" provided masker parameters :\\n\"\n                    \"{0:s}\").format(conflict_string)\n        warnings.warn(warn_str)\n    masker = masker_type(**new_masker_params)\n\n    # Forwarding potential attribute of provided masker\n    if hasattr(mask, 'mask_img_'):\n        # Allow free fit of returned mask\n        masker.mask_img = mask.mask_img_\n\n    return masker\n", "path": "nilearn/input_data/masker_validation.py"}], "after_files": [{"content": "import warnings\n\nimport numpy as np\nfrom string import Template\n\nfrom .._utils.class_inspect import get_params\nfrom .._utils.cache_mixin import _check_memory\nfrom .multi_nifti_masker import MultiNiftiMasker\nfrom .nifti_masker import NiftiMasker\n\n\ndef check_embedded_nifti_masker(estimator, multi_subject=True):\n    \"\"\"Base function for using a masker within a BaseEstimator class\n\n    This creates a masker from instance parameters :\n    - If instance contains a mask image in mask parameter,\n    we use this image as new masker mask_img, forwarding instance parameters to\n    new masker : smoothing_fwhm, standardize, detrend, low_pass= high_pass,\n    t_r, target_affine, target_shape, mask_strategy, mask_args,\n    - If instance contains a masker in mask parameter, we use a copy of\n    this masker, overriding all instance masker related parameters.\n    In all case, we forward system parameters of instance to new masker :\n    memory, memory_level, verbose, n_jobs\n\n    Parameters\n    ----------\n    instance: object, instance of BaseEstimator\n        The object that gives us the values of the parameters\n\n    multi_subject: boolean\n        Indicates whether to return a MultiNiftiMasker or a NiftiMasker\n        (the default is True)\n\n    Returns\n    -------\n    masker: MultiNiftiMasker or NiftiMasker\n        New masker\n    \"\"\"\n    masker_type = MultiNiftiMasker if multi_subject else NiftiMasker\n    estimator_params = get_params(masker_type, estimator)\n    mask = getattr(estimator, 'mask', None)\n\n    if isinstance(mask, (NiftiMasker, MultiNiftiMasker)):\n        # Creating (Multi)NiftiMasker from provided masker\n        masker_params = get_params(masker_type, mask)\n        new_masker_params = masker_params\n    else:\n        # Creating (Multi)NiftiMasker\n        # with parameters extracted from estimator\n        new_masker_params = estimator_params\n        new_masker_params['mask_img'] = mask\n    # Forwarding system parameters of instance to new masker in all case\n    if multi_subject and hasattr(estimator, 'n_jobs'):\n        # For MultiNiftiMasker only\n        new_masker_params['n_jobs'] = estimator.n_jobs\n\n    warning_msg = Template(\"Provided estimator has no $attribute attribute set.\"\n                           \"Setting $attribute to $default_value by default.\")\n\n    if hasattr(estimator, 'memory'):\n        new_masker_params['memory'] = _check_memory(estimator.memory)\n    else:\n        warnings.warn(warning_msg.substitute(attribute='memory',\n                                             default_value='Memory(location=None)'))\n        new_masker_params['memory'] = _check_memory(None)\n\n    if hasattr(estimator, 'memory_level'):\n        new_masker_params['memory_level'] = max(0, estimator.memory_level - 1)\n    else:\n        warnings.warn(warning_msg.substitute(attribute='memory_level',\n                                             default_value='0'))\n        new_masker_params['memory_level'] = 0\n\n    if hasattr(estimator, 'verbose'):\n        new_masker_params['verbose'] = estimator.verbose\n    else:\n        warnings.warn(warning_msg.substitute(attribute='verbose',\n                                             default_value='0'))\n        new_masker_params['verbose'] = 0\n\n    # Raising warning if masker override parameters\n    conflict_string = \"\"\n    for param_key in sorted(estimator_params):\n        if np.any(new_masker_params[param_key] != estimator_params[param_key]):\n            conflict_string += (\"Parameter {0} :\\n\"\n                                \"    Masker parameter {1}\"\n                                \" - overriding estimator parameter {2}\\n\"\n                                ).format(param_key,\n                                         new_masker_params[param_key],\n                                         estimator_params[param_key])\n\n    if conflict_string != \"\":\n        warn_str = (\"Overriding provided-default estimator parameters with\"\n                    \" provided masker parameters :\\n\"\n                    \"{0:s}\").format(conflict_string)\n        warnings.warn(warn_str)\n    masker = masker_type(**new_masker_params)\n\n    # Forwarding potential attribute of provided masker\n    if hasattr(mask, 'mask_img_'):\n        # Allow free fit of returned mask\n        masker.mask_img = mask.mask_img_\n\n    return masker\n", "path": "nilearn/input_data/masker_validation.py"}]}