code: def mask2spans(mask, index=None):
      
      index = list(range(len(mask))) if index is None else index
  
      mask = pd.Series(mask)
      mask = mask.astype(int).fillna(0).diff().fillna(0)
      starts = list(index[mask > 0])
      stops = list(index[mask < 0])
      if len(stops) == len(starts) - 1:
          stops += [index.values[-1]]
      spans = join_spans(join_spans(zip(starts, stops)))
      return spans
docs: Convert a sequence of bools (True/False) into a list of the start and stop of the True "sections" or spans