code: def average_time_bounds(ds):
      
      bounds = ds[TIME_BOUNDS_STR]
      new_times = bounds.mean(dim=BOUNDS_STR, keep_attrs=True)
      new_times = new_times.drop(TIME_STR).rename(TIME_STR)
      new_times[TIME_STR] = new_times
      return new_times
docs: Return the average of each set of time bounds in the Dataset.
  
      Useful for creating a new time array to replace the Dataset's native time
      array, in the case that the latter matches either the start or end bounds.
      This can cause errors in grouping (akin to an off-by-one error) if the
      timesteps span e.g. one full month each.  Note that the Dataset's times
      must not have already undergone "CF decoding", wherein they are converted
      from floats using the 'units' attribute into datetime objects.
  
      Parameters
      ----------
      ds : xarray.Dataset
          A Dataset containing a time bounds array with name matching
          internal_names.TIME_BOUNDS_STR.  This time bounds array must have two
          dimensions, one of which's coordinates is the Dataset's time array, and
          the other is length-2.
  
      Returns
      -------
      xarray.DataArray
          The mean of the start and end times of each timestep in the original
          Dataset.
  
      Raises
      ------
      ValueError
          If the time bounds array doesn't match the shape specified above.