code: def _check_columns(events):
      """Check events has onset and duration numeric columns with no NaN."""
      for col_name in ["onset", "duration"]:
          if col_name not in events.columns:
              raise ValueError(
                  f"The provided events data has no {col_name} column."
              )
          if events[col_name].isnull().any():
              raise ValueError(
                  f"The following column must not contain nan values: {col_name}"
              )
          # Make sure we have a numeric type for duration
          if not is_numeric_dtype(events[col_name]):
              try:
                  events = events.astype({col_name: float})
              except ValueError as e:
                  raise ValueError(
                      f"Could not cast {col_name} to float in events data."
                  ) from e
      return events
  
file_path: nilearn/nilearn/glm/first_level/experimental_paradigm.py
imports: import warnings
  import pandas
  from pandas.api.types import is_numeric_dtype
label_desc: Use image node_id 2 for calling a global function with example usage: _check_columns(events) and returns: events