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