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

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        The training input samples. Internally, its dtype will be converted
        to ``dtype=np.float32``. If a sparse matrix is provided, it will be
        converted into a sparse ``csc_matrix``.

    y : array-like of shape (n_samples,) or (n_samples, n_outputs)
        The target values (class labels in classification, real numbers in
        regression).

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights. If None, then samples are equally weighted. Splits
        that would create child nodes with net zero or negative weight are
        ignored while searching for a split in each node. In the case of
        classification, splits are also ignored if they would result in any
        single class carrying a negative weight in either child node.

    Returns
    -------
    self : object
    """
    # Validate or convert input data
    X = check_array(X, accept_sparse="csc", dtype=DTYPE)
    y = check_array(y, accept_sparse="csc", ensure_2d=False, dtype=None)
    if sample_weight is not None:
        sample_weight = _check_sample_weight(sample_weight, X)
    if issparse(X):
        # Pre-sort indices to avoid that each individual tree of the
        # ensemble sorts the indices.
        X.sort_indices()

    # Remap output
    self.n_features_ = X.shape[1]

    y = np.atleast_1d(y)
    if y.ndim == 2 and y.shape[1] == 1:
        warn(
            "A column-vector y was passed when a 1d array was"
            " expected. Please change the shape of y to "
            "(n_samples,), for example using ravel().",
            DataConversionWarning,
            stacklevel=2,
        )

    if y.ndim == 1:
        # reshape is necessary to preserve the data contiguity against vs
        # [:, np.newaxis] that does not.
        y = np.reshape(y, (-1, 1))

    self.n_outputs_ = y.shape[1]

    y, expanded_class_weight = self._validate_y_class_weight(y)

    if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
        y = np.ascontiguousarray(y, dtype=DOUBLE)

    if expanded_class_weight is not None:
        if sample_weight is not None:
            sample_weight = sample_weight * expanded_class_weight
        else:
            sample_weight = expanded_class_weight

    # Get bootstrap sample size
    n_samples_bootstrap = _get_n_samples_bootstrap(
        n_samples=X.shape[0], max_samples=self.max_samples
    )

    # Check parameters
    self._validate_estimator()

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

    random_state = check_random_state(self.random_state)

    if not self.warm_start or not hasattr(self, "estimators_"):
        # Free allocated memory, if any
        self.estimators_ = []

    n_more_estimators = self.n_estimators - len(self.estimators_)

    if n_more_estimators < 0:
        raise ValueError(
            "n_estimators=%d must be larger or equal to "
            "len(estimators_)=%d when warm_start==True"
            % (self.n_estimators, len(self.estimators_))
        )

    elif n_more_estimators == 0:
        warn(
            "Warm-start fitting without increasing n_estimators does not fit new trees."
        )
    else:
        if self.warm_start and len(self.estimators_) > 0:
            # We draw from the random state to get the random state we
            # would have got if we hadn't used a warm_start.
            random_state.randint(MAX_INT, size=len(self.estimators_))

        trees = [
            self._make_estimator(append=False, random_state=random_state)
            for i in range(n_more_estimators)
        ]

        # Parallel loop: we prefer the threading backend as the Cython code
        # for fitting the trees is internally releasing the Python GIL
        # making threading more efficient than multiprocessing in
        # that case. However, for joblib 0.12+ we respect any
        # parallel_backend contexts set at a higher level,
        # since correctness does not rely on using threads.
        trees = Parallel(
            n_jobs=self.n_jobs,
            verbose=self.verbose,
            **_joblib_parallel_args(prefer="threads"),
        )(
            delayed(_parallel_build_trees)(
                t,
                self,
                X,
                y,
                sample_weight,
                i,
                len(trees),
                verbose=self.verbose,
                class_weight=self.class_weight,
                n_samples_bootstrap=n_samples_bootstrap,
            )
            for i, t in enumerate(trees)
        )

        # Collect newly grown trees
        self.estimators_.extend(trees)

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

    # Decapsulate classes_ attributes
    if hasattr(self, "classes_") and self.n_outputs_ == 1:
        self.n_classes_ = self.n_classes_[0]
        self.classes_ = self.classes_[0]

    return self


# Traceback (ValueError)
In [2]: from sklearn.ensemble import RandomForestClassifier

In [3]: from sklearn.datasets import fetch_rcv1

In [4]: X, y = fetch_rcv1(return_X_y=True)

In [5]: rfc = RandomForestClassifier()

In [6]: rfc.fit(X[:2], y[:2])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-3f7ac458bf48> in <module>
----> 1 rfc.fit(X[:2], y[:2])

~/scikit-learn/sklearn/ensemble/_forest.py in fit(self, X, y, sample_weight)
319         self.n_outputs_ = y.shape[1]
320
--> 321         y, expanded_class_weight = self._validate_y_class_weight(y)
322
323         if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:

~/scikit-learn/sklearn/ensemble/_forest.py in _validate_y_class_weight(self, y)
539
540     def _validate_y_class_weight(self, y):
--> 541         check_classification_targets(y)
542
543         y = np.copy(y)

~/scikit-learn/sklearn/utils/multiclass.py in check_classification_targets(y)
167     if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
168                       'multilabel-indicator', 'multilabel-sequences']:
--> 169         raise ValueError("Unknown label type: %r" % y_type)
170
171

ValueError: Unknown label type: 'unknown'

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

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        The training input samples. Internally, its dtype will be converted
        to ``dtype=np.float32``. If a sparse matrix is provided, it will be
        converted into a sparse ``csc_matrix``.

    y : array-like of shape (n_samples,) or (n_samples, n_outputs)
        The target values (class labels in classification, real numbers in
        regression).

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights. If None, then samples are equally weighted. Splits
        that would create child nodes with net zero or negative weight are
        ignored while searching for a split in each node. In the case of
        classification, splits are also ignored if they would result in any
        single class carrying a negative weight in either child node.

    Returns
    -------
    self : object
    """
    # Validate and convert input data
    if issparse(y):
        raise ValueError("sparse multilabel-indicator for y is not supported.")
    X = check_array(X, accept_sparse="csc", dtype=DTYPE)
    y = check_array(y, ensure_2d=False, dtype=None)
    if sample_weight is not None:
        sample_weight = _check_sample_weight(sample_weight, X)

    if issparse(X):
        # Pre-sort indices to avoid that each individual tree of the
        # ensemble sorts the indices.
        X.sort_indices()

    # Remap output
    self.n_features_ = X.shape[1]

    y = np.atleast_1d(y)
    if y.ndim == 2 and y.shape[1] == 1:
        warn(
            "A column-vector y was passed when a 1d array was"
            " expected. Please change the shape of y to "
            "(n_samples,), for example using ravel().",
            DataConversionWarning,
            stacklevel=2,
        )

    if y.ndim == 1:
        # reshape is necessary to preserve the data contiguity against vs
        # [:, np.newaxis] that does not.
        y = np.reshape(y, (-1, 1))

    self.n_outputs_ = y.shape[1]

    y, expanded_class_weight = self._validate_y_class_weight(y)

    if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
        y = np.ascontiguousarray(y, dtype=DOUBLE)

    if expanded_class_weight is not None:
        if sample_weight is not None:
            sample_weight = sample_weight * expanded_class_weight
        else:
            sample_weight = expanded_class_weight

    # Get bootstrap sample size
    n_samples_bootstrap = _get_n_samples_bootstrap(
        n_samples=X.shape[0], max_samples=self.max_samples
    )

    # Check parameters
    self._validate_estimator()

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

    random_state = check_random_state(self.random_state)

    if not self.warm_start or not hasattr(self, "estimators_"):
        # Free allocated memory, if any
        self.estimators_ = []

    n_more_estimators = self.n_estimators - len(self.estimators_)

    if n_more_estimators < 0:
        raise ValueError(
            "n_estimators=%d must be larger or equal to "
            "len(estimators_)=%d when warm_start==True"
            % (self.n_estimators, len(self.estimators_))
        )

    elif n_more_estimators == 0:
        warn(
            "Warm-start fitting without increasing n_estimators does not fit new trees."
        )
    else:
        if self.warm_start and len(self.estimators_) > 0:
            # We draw from the random state to get the random state we
            # would have got if we hadn't used a warm_start.
            random_state.randint(MAX_INT, size=len(self.estimators_))

        trees = [
            self._make_estimator(append=False, random_state=random_state)
            for i in range(n_more_estimators)
        ]

        # Parallel loop: we prefer the threading backend as the Cython code
        # for fitting the trees is internally releasing the Python GIL
        # making threading more efficient than multiprocessing in
        # that case. However, for joblib 0.12+ we respect any
        # parallel_backend contexts set at a higher level,
        # since correctness does not rely on using threads.
        trees = Parallel(
            n_jobs=self.n_jobs,
            verbose=self.verbose,
            **_joblib_parallel_args(prefer="threads"),
        )(
            delayed(_parallel_build_trees)(
                t,
                self,
                X,
                y,
                sample_weight,
                i,
                len(trees),
                verbose=self.verbose,
                class_weight=self.class_weight,
                n_samples_bootstrap=n_samples_bootstrap,
            )
            for i, t in enumerate(trees)
        )

        # Collect newly grown trees
        self.estimators_.extend(trees)

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

    # Decapsulate classes_ attributes
    if hasattr(self, "classes_") and self.n_outputs_ == 1:
        self.n_classes_ = self.n_classes_[0]
        self.classes_ = self.classes_[0]

    return self