def _iter_test_indices(self, X, y, labels):
        if labels is None:
            raise ValueError("The labels parameter should not be None")

        unique_labels, labels = np.unique(labels, return_inverse=True)
        n_labels = len(unique_labels)

        if n_labels > self.n_folds:
            raise ValueError("Cannot have number of folds n_folds=%d greater"
                             " than the number of labels: %d."
                             % (self.n_folds, n_labels))

        # Weight labels by their number of occurrences
        n_samples_per_label = np.bincount(labels)

        # Distribute the most frequent labels first
        indices = np.argsort(n_samples_per_label)[::-1]
        n_samples_per_label = n_samples_per_label[indices]

        # Total weight of each fold
        n_samples_per_fold = np.zeros(self.n_folds)

        # Mapping from label index to fold index
        label_to_fold = np.zeros(len(unique_labels))

        # Distribute samples by adding the largest weight to the lightest fold
        for label_index, weight in enumerate(n_samples_per_label):
            lightest_fold = np.argmin(n_samples_per_fold)
            n_samples_per_fold[lightest_fold] += weight
            label_to_fold[indices[label_index]] = lightest_fold

        indices = label_to_fold[labels]

        for f in range(self.n_folds):
            yield np.where(indices == f)[0]
dataset/ETHPy150Open scikit-learn/scikit-learn/sklearn/model_selection/_split.py/LabelKFold._iter_test_indices/swapped operands of `>`