prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  check_paradigm should check for invalid keys in passed dict
  Using the old `nipy` user logic, I passed `amplitude=somethx` instead of `modulation=somethx` in the `make_design_matrix`. I didn't crash but the values where ignored (e.g Error: unknown param, etc.). A default value of 1 was forced...
  
  
  --- 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/glm/first_level/experimental_paradigm.py`
  Content:
  ```
  1 """
  2 An experimental protocol is handled as a pandas DataFrame
  3 that includes an 'onset' field.
  4 
  5 This yields the onset time of the events in the experimental paradigm.
  6 It can also contain:
  7 
  8     * a 'trial_type' field that yields the condition identifier.
  9     * a 'duration' field that yields event duration (for so-called block
  10         paradigms).
  11     * a 'modulation' field that associated a scalar value to each event.
  12 
  13 Author: Bertrand Thirion, 2015
  14 
  15 """
  16 import warnings
  17 
  18 import numpy as np
  19 
  20 
  21 def check_events(events):
  22     """Test that the events data describes a valid experimental paradigm
  23 
  24     It is valid if the events data  has an 'onset' key.
  25 
  26     Parameters
  27     ----------
  28     events : pandas DataFrame
  29         Events data that describes a functional experimental paradigm.
  30 
  31     Returns
  32     -------
  33     trial_type : array of shape (n_events,), dtype='s'
  34         Per-event experimental conditions identifier.
  35         Defaults to np.repeat('dummy', len(onsets)).
  36 
  37     onset : array of shape (n_events,), dtype='f'
  38         Per-event onset time (in seconds)
  39 
  40     duration : array of shape (n_events,), dtype='f'
  41         Per-event durantion, (in seconds)
  42         defaults to zeros(n_events) when no duration is provided
  43 
  44     modulation : array of shape (n_events,), dtype='f'
  45         Per-event modulation, (in seconds)
  46         defaults to ones(n_events) when no duration is provided.
  47 
  48     """
  49     if 'onset' not in events.keys():
  50         raise ValueError('The provided events data has no onset column.')
  51     if 'duration' not in events.keys():
  52         raise ValueError('The provided events data has no duration column.')
  53 
  54     onset = np.array(events['onset'])
  55     duration = np.array(events['duration']).astype(np.float)
  56     n_events = len(onset)
  57     trial_type = np.array(events['trial_type'])
  58     modulation = np.ones(n_events)
  59     if 'trial_type' not in events.keys():
  60         warnings.warn("'trial_type' column not found "
  61                       "in the given events data.")
  62         trial_type = np.repeat('dummy', n_events)
  63     if 'modulation' in events.keys():
  64         warnings.warn("'modulation' column found in the given events data.")
  65         modulation = np.array(events['modulation']).astype(np.float)
  66     return trial_type, onset, duration, modulation
  67
  ```
  --- 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/glm/first_level/experimental_paradigm.py b/nilearn/glm/first_level/experimental_paradigm.py
  --- a/nilearn/glm/first_level/experimental_paradigm.py
  +++ b/nilearn/glm/first_level/experimental_paradigm.py
  @@ -17,6 +17,11 @@
   
   import numpy as np
   
  +VALID_FIELDS = set(["onset",
  +                    "duration",
  +                    "trial_type",
  +                    "modulation",
  +                    ])
   
   def check_events(events):
       """Test that the events data describes a valid experimental paradigm
  @@ -54,13 +59,19 @@
       onset = np.array(events['onset'])
       duration = np.array(events['duration']).astype(np.float)
       n_events = len(onset)
  -    trial_type = np.array(events['trial_type'])
       modulation = np.ones(n_events)
       if 'trial_type' not in events.keys():
           warnings.warn("'trial_type' column not found "
                         "in the given events data.")
           trial_type = np.repeat('dummy', n_events)
  +    else:
  +        trial_type = np.array(events['trial_type'])
       if 'modulation' in events.keys():
           warnings.warn("'modulation' column found in the given events data.")
           modulation = np.array(events['modulation']).astype(np.float)
  +    for event,_ in events.items():
  +        if event not in VALID_FIELDS:
  +            warnings.warn("Unexpected key `{}` in events "
  +                          "will be ignored.".format(
  +                              event))
       return trial_type, onset, duration, modulation
  
verification_info: {"golden_diff": "diff --git a/nilearn/glm/first_level/experimental_paradigm.py b/nilearn/glm/first_level/experimental_paradigm.py\n--- a/nilearn/glm/first_level/experimental_paradigm.py\n+++ b/nilearn/glm/first_level/experimental_paradigm.py\n@@ -17,6 +17,11 @@\n \n import numpy as np\n \n+VALID_FIELDS = set([\"onset\",\n+                    \"duration\",\n+                    \"trial_type\",\n+                    \"modulation\",\n+                    ])\n \n def check_events(events):\n     \"\"\"Test that the events data describes a valid experimental paradigm\n@@ -54,13 +59,19 @@\n     onset = np.array(events['onset'])\n     duration = np.array(events['duration']).astype(np.float)\n     n_events = len(onset)\n-    trial_type = np.array(events['trial_type'])\n     modulation = np.ones(n_events)\n     if 'trial_type' not in events.keys():\n         warnings.warn(\"'trial_type' column not found \"\n                       \"in the given events data.\")\n         trial_type = np.repeat('dummy', n_events)\n+    else:\n+        trial_type = np.array(events['trial_type'])\n     if 'modulation' in events.keys():\n         warnings.warn(\"'modulation' column found in the given events data.\")\n         modulation = np.array(events['modulation']).astype(np.float)\n+    for event,_ in events.items():\n+        if event not in VALID_FIELDS:\n+            warnings.warn(\"Unexpected key `{}` in events \"\n+                          \"will be ignored.\".format(\n+                              event))\n     return trial_type, onset, duration, modulation\n", "issue": "check_paradigm should check for invalid keys in passed dict\nUsing the old `nipy` user logic, I passed `amplitude=somethx` instead of `modulation=somethx` in the `make_design_matrix`. I didn't crash but the values where ignored (e.g Error: unknown param, etc.). A default value of 1 was forced...\n\n", "before_files": [{"content": "\"\"\"\nAn experimental protocol is handled as a pandas DataFrame\nthat includes an 'onset' field.\n\nThis yields the onset time of the events in the experimental paradigm.\nIt can also contain:\n\n    * a 'trial_type' field that yields the condition identifier.\n    * a 'duration' field that yields event duration (for so-called block\n        paradigms).\n    * a 'modulation' field that associated a scalar value to each event.\n\nAuthor: Bertrand Thirion, 2015\n\n\"\"\"\nimport warnings\n\nimport numpy as np\n\n\ndef check_events(events):\n    \"\"\"Test that the events data describes a valid experimental paradigm\n\n    It is valid if the events data  has an 'onset' key.\n\n    Parameters\n    ----------\n    events : pandas DataFrame\n        Events data that describes a functional experimental paradigm.\n\n    Returns\n    -------\n    trial_type : array of shape (n_events,), dtype='s'\n        Per-event experimental conditions identifier.\n        Defaults to np.repeat('dummy', len(onsets)).\n\n    onset : array of shape (n_events,), dtype='f'\n        Per-event onset time (in seconds)\n\n    duration : array of shape (n_events,), dtype='f'\n        Per-event durantion, (in seconds)\n        defaults to zeros(n_events) when no duration is provided\n\n    modulation : array of shape (n_events,), dtype='f'\n        Per-event modulation, (in seconds)\n        defaults to ones(n_events) when no duration is provided.\n\n    \"\"\"\n    if 'onset' not in events.keys():\n        raise ValueError('The provided events data has no onset column.')\n    if 'duration' not in events.keys():\n        raise ValueError('The provided events data has no duration column.')\n\n    onset = np.array(events['onset'])\n    duration = np.array(events['duration']).astype(np.float)\n    n_events = len(onset)\n    trial_type = np.array(events['trial_type'])\n    modulation = np.ones(n_events)\n    if 'trial_type' not in events.keys():\n        warnings.warn(\"'trial_type' column not found \"\n                      \"in the given events data.\")\n        trial_type = np.repeat('dummy', n_events)\n    if 'modulation' in events.keys():\n        warnings.warn(\"'modulation' column found in the given events data.\")\n        modulation = np.array(events['modulation']).astype(np.float)\n    return trial_type, onset, duration, modulation\n", "path": "nilearn/glm/first_level/experimental_paradigm.py"}], "after_files": [{"content": "\"\"\"\nAn experimental protocol is handled as a pandas DataFrame\nthat includes an 'onset' field.\n\nThis yields the onset time of the events in the experimental paradigm.\nIt can also contain:\n\n    * a 'trial_type' field that yields the condition identifier.\n    * a 'duration' field that yields event duration (for so-called block\n        paradigms).\n    * a 'modulation' field that associated a scalar value to each event.\n\nAuthor: Bertrand Thirion, 2015\n\n\"\"\"\nimport warnings\n\nimport numpy as np\n\nVALID_FIELDS = set([\"onset\",\n                    \"duration\",\n                    \"trial_type\",\n                    \"modulation\",\n                    ])\n\ndef check_events(events):\n    \"\"\"Test that the events data describes a valid experimental paradigm\n\n    It is valid if the events data  has an 'onset' key.\n\n    Parameters\n    ----------\n    events : pandas DataFrame\n        Events data that describes a functional experimental paradigm.\n\n    Returns\n    -------\n    trial_type : array of shape (n_events,), dtype='s'\n        Per-event experimental conditions identifier.\n        Defaults to np.repeat('dummy', len(onsets)).\n\n    onset : array of shape (n_events,), dtype='f'\n        Per-event onset time (in seconds)\n\n    duration : array of shape (n_events,), dtype='f'\n        Per-event durantion, (in seconds)\n        defaults to zeros(n_events) when no duration is provided\n\n    modulation : array of shape (n_events,), dtype='f'\n        Per-event modulation, (in seconds)\n        defaults to ones(n_events) when no duration is provided.\n\n    \"\"\"\n    if 'onset' not in events.keys():\n        raise ValueError('The provided events data has no onset column.')\n    if 'duration' not in events.keys():\n        raise ValueError('The provided events data has no duration column.')\n\n    onset = np.array(events['onset'])\n    duration = np.array(events['duration']).astype(np.float)\n    n_events = len(onset)\n    modulation = np.ones(n_events)\n    if 'trial_type' not in events.keys():\n        warnings.warn(\"'trial_type' column not found \"\n                      \"in the given events data.\")\n        trial_type = np.repeat('dummy', n_events)\n    else:\n        trial_type = np.array(events['trial_type'])\n    if 'modulation' in events.keys():\n        warnings.warn(\"'modulation' column found in the given events data.\")\n        modulation = np.array(events['modulation']).astype(np.float)\n    for event,_ in events.items():\n        if event not in VALID_FIELDS:\n            warnings.warn(\"Unexpected key `{}` in events \"\n                          \"will be ignored.\".format(\n                              event))\n    return trial_type, onset, duration, modulation\n", "path": "nilearn/glm/first_level/experimental_paradigm.py"}]}