def __iter__(self):
        n = len(self.data)
        index = self.data.index
        indices = range(n)
        foldsize = n / self.num_folds
        folds = []

        if self.seed is not None:
            np.random.seed(self.seed)

        for i in range(self.repeat):
            watertight_bins = self.data.groupby(self.leakage_column)[self.data.columns[0]].count()
            watertight_bins = watertight_bins.reindex(np.random.permutation(watertight_bins.index))
            watertight_bins_cum = watertight_bins.cumsum()
            for i in range(self.num_folds):
                test_bins = watertight_bins_cum[(watertight_bins_cum >  i * foldsize) &
                                                (watertight_bins_cum <= (i+1) * foldsize)]
                test =index[self.data[self.leakage_column].isin(test_bins.index)]
                train = index - test

                # Sanity checks
                assert not (train & test)
                if np.abs(len(test) - foldsize) > 0.05*foldsize:
                    # Folds will not be exact in size, but a warning will be
                    # emitted if they are far from the expected value.
                    logging.warn("Fold deviated from expected size. Target: {target} Actual: {actual}".format(target=foldsize, actual=len(test)))
                fold = (pd.Index(train), pd.Index(test))
                yield fold
dataset/ETHPy150Open kvh/ramp/ramp/folds.py/WatertightFolds.__iter__/original