# Buggy code
def _iter_indices(self, X, y, groups=None):
    n_samples = _num_samples(X)
    n_train, n_test = _validate_shuffle_split(
        n_samples, self.test_size, self.train_size
    )
    classes, y_indices = np.unique(y, return_inverse=True)
    n_classes = classes.shape[0]

    class_counts = bincount(y_indices)
    if np.min(class_counts) < 2:
        raise ValueError(
            "The least populated class in y has only 1"
            " member, which is too few. The minimum"
            " number of groups for any class cannot"
            " be less than 2."
        )

    if n_train < n_classes:
        raise ValueError(
            "The train_size = %d should be greater or "
            "equal to the number of classes = %d" % (n_train, n_classes)
        )
    if n_test < n_classes:
        raise ValueError(
            "The test_size = %d should be greater or "
            "equal to the number of classes = %d" % (n_test, n_classes)
        )

    rng = check_random_state(self.random_state)

    for _ in range(self.n_splits):
        # if there are ties in the class-counts, we want
        # to make sure to break them anew in each iteration
        n_i = _approximate_mode(class_counts, n_train, rng)
        class_counts_remaining = class_counts - n_i
        t_i = _approximate_mode(class_counts_remaining, n_test, rng)

        train = []
        test = []

        for i, class_i in enumerate(classes):
            permutation = rng.permutation(class_counts[i])
            perm_indices_class_i = np.where((y == class_i))[0][permutation]

            train.extend(perm_indices_class_i[: n_i[i]])
            test.extend(perm_indices_class_i[n_i[i] : n_i[i] + t_i[i]])
        train = rng.permutation(train)
        test = rng.permutation(test)

        yield train, test


# Traceback (ImportError)
In [3]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/__init__.py in <module>()
15 from ._split import check_cv
16
---> 17 from ._validation import cross_val_score
18 from ._validation import cross_val_predict
19 from ._validation import learning_curve

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/_validation.py in <module>()
25 from ..utils.fixes import astype
26 from ..utils.validation import _is_arraylike, _num_samples
---> 27 from ..utils.metaestimators import _safe_split
28 from ..externals.joblib import Parallel, delayed, logger
29 from ..metrics.scorer import check_scoring

ImportError: cannot import name _safe_split

# Fixed code
def _iter_indices(self, X, y, groups=None):
    n_samples = _num_samples(X)
    y = check_array(y, ensure_2d=False, dtype=None)
    n_train, n_test = _validate_shuffle_split(
        n_samples, self.test_size, self.train_size
    )
    classes, y_indices = np.unique(y, return_inverse=True)
    n_classes = classes.shape[0]

    class_counts = bincount(y_indices)
    if np.min(class_counts) < 2:
        raise ValueError(
            "The least populated class in y has only 1"
            " member, which is too few. The minimum"
            " number of groups for any class cannot"
            " be less than 2."
        )

    if n_train < n_classes:
        raise ValueError(
            "The train_size = %d should be greater or "
            "equal to the number of classes = %d" % (n_train, n_classes)
        )
    if n_test < n_classes:
        raise ValueError(
            "The test_size = %d should be greater or "
            "equal to the number of classes = %d" % (n_test, n_classes)
        )

    rng = check_random_state(self.random_state)

    for _ in range(self.n_splits):
        # if there are ties in the class-counts, we want
        # to make sure to break them anew in each iteration
        n_i = _approximate_mode(class_counts, n_train, rng)
        class_counts_remaining = class_counts - n_i
        t_i = _approximate_mode(class_counts_remaining, n_test, rng)

        train = []
        test = []

        for i, class_i in enumerate(classes):
            permutation = rng.permutation(class_counts[i])
            perm_indices_class_i = np.where((y == class_i))[0][permutation]

            train.extend(perm_indices_class_i[: n_i[i]])
            test.extend(perm_indices_class_i[n_i[i] : n_i[i] + t_i[i]])
        train = rng.permutation(train)
        test = rng.permutation(test)

        yield train, test