code: def slice_around_gaps (values, maxgap):
      
      if not (maxgap > 0):
          # above test catches NaNs, other weird cases
          raise ValueError ('maxgap must be positive; got %r' % maxgap)
  
      values = np.asarray (values)
      delta = values[1:] - values[:-1]
  
      if np.any (delta < 0):
          raise ValueError ('values must be in nondecreasing order')
  
      whgap = np.where (delta > maxgap)[0] + 1
      prev_idx = None
  
      for gap_idx in whgap:
          yield slice (prev_idx, gap_idx)
          prev_idx = gap_idx
  
      yield slice (prev_idx, None)
docs: Given an ordered array of values, generate a set of slices that traverse
      all of the values. Within each slice, no gap between adjacent values is
      larger than `maxgap`. In other words, these slices break the array into
      chunks separated by gaps of size larger than maxgap.