# Buggy code
def fit(self, X, y, sample_weight=None):
    """Build a Bagging ensemble of estimators from the training
       set (X, y).

    Parameters
    ----------
    X : array-like of shape = [n_samples, n_features]
        The training input samples.

    y : array-like, shape = [n_samples]
        The target values (class labels in classification, real numbers in
        regression).

    sample_weight : array-like, shape = [n_samples] or None
        Sample weights. If None, then samples are equally weighted.
        Note that this is supported only if the base estimator supports
        sample weighting.

    Returns
    -------
    self : object
        Returns self.
    """
    random_state = check_random_state(self.random_state)

    # Convert data
    X, y = check_arrays(X, y)

    # Remap output
    n_samples, self.n_features_ = X.shape
    y = self._validate_y(y)

    # Check parameters
    self._validate_estimator()

    if isinstance(self.max_samples, (numbers.Integral, np.integer)):
        max_samples = self.max_samples
    else:  # float
        max_samples = int(self.max_samples * X.shape[0])

    if not (0 < max_samples <= X.shape[0]):
        raise ValueError("max_samples must be in (0, n_samples]")

    if isinstance(self.max_features, (numbers.Integral, np.integer)):
        max_features = self.max_features
    else:  # float
        max_features = int(self.max_features * self.n_features_)

    if not (0 < max_features <= self.n_features_):
        raise ValueError("max_features must be in (0, n_features]")

    if not self.bootstrap and self.oob_score:
        raise ValueError("Out of bag estimation only available if bootstrap=True")

    # Free allocated memory, if any
    self.estimators_ = None

    # Parallel loop
    n_jobs, n_estimators, starts = _partition_estimators(self)
    seeds = random_state.randint(MAX_INT, size=self.n_estimators)

    all_results = Parallel(n_jobs=n_jobs, verbose=self.verbose)(
        delayed(_parallel_build_estimators)(
            n_estimators[i],
            self,
            X,
            y,
            sample_weight,
            seeds[starts[i] : starts[i + 1]],
            verbose=self.verbose,
        )
        for i in range(n_jobs)
    )

    # Reduce
    self.estimators_ = list(itertools.chain.from_iterable(t[0] for t in all_results))
    self.estimators_samples_ = list(
        itertools.chain.from_iterable(t[1] for t in all_results)
    )
    self.estimators_features_ = list(
        itertools.chain.from_iterable(t[2] for t in all_results)
    )

    if self.oob_score:
        self._set_oob_score(X, y)

    return self


# Traceback (IndexError)
======================================================================
ERROR: sklearn.tests.test_common.test_regressors_train('RANSACRegressor', <class 'sklearn.linear_model.ransac.RANSACRegr
essor'>, array([[-0.44836249, -0.47282444, -1.20608008, ..., -0.75500806,
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\Python27\lib\site-packages\sklearn\tests\test_common.py", line 850, in check_regressors_train
assert_raises(ValueError, regressor.fit, X, y[:-1])
File "C:\Python27\lib\unittest\case.py", line 473, in assertRaises
callableObj(*args, **kwargs)
File "C:\Python27\lib\site-packages\sklearn\linear_model\ransac.py", line 261, in fit
y_subset = y[subset_idxs]
IndexError: index 199 is out of bounds for axis 0 with size 199

# Fixed code
def fit(self, X, y, sample_weight=None):
    """Build a Bagging ensemble of estimators from the training
       set (X, y).

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape = [n_samples, n_features]
        The training input samples. Sparse matrices are accepted only if
        they are supported by the base estimator.

    y : array-like, shape = [n_samples]
        The target values (class labels in classification, real numbers in
        regression).

    sample_weight : array-like, shape = [n_samples] or None
        Sample weights. If None, then samples are equally weighted.
        Note that this is supported only if the base estimator supports
        sample weighting.

    Returns
    -------
    self : object
        Returns self.
    """
    random_state = check_random_state(self.random_state)

    # Convert data
    X, y = check_arrays(X, y)

    # Remap output
    n_samples, self.n_features_ = X.shape
    y = self._validate_y(y)

    # Check parameters
    self._validate_estimator()

    if isinstance(self.max_samples, (numbers.Integral, np.integer)):
        max_samples = self.max_samples
    else:  # float
        max_samples = int(self.max_samples * X.shape[0])

    if not (0 < max_samples <= X.shape[0]):
        raise ValueError("max_samples must be in (0, n_samples]")

    if isinstance(self.max_features, (numbers.Integral, np.integer)):
        max_features = self.max_features
    else:  # float
        max_features = int(self.max_features * self.n_features_)

    if not (0 < max_features <= self.n_features_):
        raise ValueError("max_features must be in (0, n_features]")

    if not self.bootstrap and self.oob_score:
        raise ValueError("Out of bag estimation only available if bootstrap=True")

    # Free allocated memory, if any
    self.estimators_ = None

    # Parallel loop
    n_jobs, n_estimators, starts = _partition_estimators(self)
    seeds = random_state.randint(MAX_INT, size=self.n_estimators)

    all_results = Parallel(n_jobs=n_jobs, verbose=self.verbose)(
        delayed(_parallel_build_estimators)(
            n_estimators[i],
            self,
            X,
            y,
            sample_weight,
            seeds[starts[i] : starts[i + 1]],
            verbose=self.verbose,
        )
        for i in range(n_jobs)
    )

    # Reduce
    self.estimators_ = list(itertools.chain.from_iterable(t[0] for t in all_results))
    self.estimators_samples_ = list(
        itertools.chain.from_iterable(t[1] for t in all_results)
    )
    self.estimators_features_ = list(
        itertools.chain.from_iterable(t[2] for t in all_results)
    )

    if self.oob_score:
        self._set_oob_score(X, y)

    return self