def METHOD_NAME(levels):
    """Assign a unique integer to each run of identical values.
    Repeated but non-consecutive values will be assigned different integers.
    """
    return levels.diff().fillna(0).abs().cumsum().astype(int)