def _identify_runs(hypno):
    """
    Identify runs of successive sleep types, number them and add lengths of each run.
    Grouping of runs done for each of Wake, NREM and REM.

    Parameters
    ----------
    hypno : pd.DataFrame
        Hypnogram dataframe obtained through _read_hypno().

    Returns
    -------
    hypno : pd.DataFrame
        Hypnogram with added columns for successive sleep runs and lengths.

    """
    # Get successively non-identifical sleep types -> Add up to get runs/chains
    hypno.loc[:, "Run"] = hypno["Sleep"].ne(hypno["Sleep"].shift()).cumsum()

    # Merge run number with sleep type for unique identification
    hypno["Sleep_Run"] = hypno["Sleep"] + "_" + hypno["Run"].astype("str").str.zfill(3)

    # Add length of each run using groupby and transform with sum
    hypno["Sleep_Runlength"] = hypno.groupby("Sleep_Run")["Duration"].transform("sum")

    return hypno