def GetIntervals(i_outside_allowable_range):
  """Detects intervals during which a time series is outside allowable range.

  Args:
    i_outside_allowable_range: list of indices where the value is
                               above or below the allowable range of values.

  Returns:
    A list of couple of indices marking the beginning and the end of an
    interval of values outside of the allowable range.
  """
  intervals = []

  if i_outside_allowable_range.size > 0:
    i_begin = i_outside_allowable_range[0]

    for i in range(len(i_outside_allowable_range) - 1):
      if i_outside_allowable_range[i + 1] > i_outside_allowable_range[i] + 1:
        intervals.append((i_begin, i_outside_allowable_range[i]))
        i_begin = i_outside_allowable_range[i + 1]
    intervals.append((i_begin, i_outside_allowable_range[-1]))

  return intervals