def verify_identifiers(identifiers, n_items):
    """Ensure that identifiers has a compatible length and that its elements
    are unique"""
    if identifiers is None:
        return identifiers

    identifiers = np.array(identifiers, copy=False)

    # Check length for consistency
    if len(identifiers) != n_items:
        raise ValueError("identifiers has inconsistent dimension.")

    # Check that identifiers are unique
    if len(np.unique(identifiers)) != n_items:
        raise ValueError("identifiers contains duplicate values.")

    return identifiers
Ensure that identifiers has a compatible length and that its elements
    are unique