def check_qids(qids):
    """Asserts that query ids are grouped into contiguous blocks.

    Note that query ids do not have to be sorted.

    Parameters
    ----------
    qids : array_like of shape = [n_samples]
        List of query ids.

    Returns
    -------
    int
        Number of unique query ids in `qids`.

    Raises
    ------
    ValueError
        If any two query ids are not in the same contiguous block.
        e.g. ``[1, 1, 3, 3, 2, 2, 3]``

    """
    seen_qids = set()
    prev_qid = None

    for qid in qids:
        assert qid is not None
        if qid != prev_qid:
            if qid in seen_qids:
                raise ValueError('Samples must be grouped by qid.')
            seen_qids.add(qid)
            prev_qid = qid

    return len(seen_qids)
dataset/ETHPy150Open jma127/pyltr/pyltr/util/group.py/check_qids/original