# Buggy code
def _transform(self, X):
    """Assumes X contains only categorical features."""
    X = check_array(X, dtype=np.int)
    if np.any(X < 0):
        raise ValueError("X needs to contain only non-negative integers.")
    n_samples, n_features = X.shape

    indices = self.feature_indices_
    if n_features != indices.shape[0] - 1:
        raise ValueError(
            "X has different shape than during fitting."
            " Expected %d, got %d." % (indices.shape[0] - 1, n_features)
        )

    # We use only those catgorical features of X that are known using fit.
    # i.e lesser than n_values_ using mask.
    # This means, if self.handle_unknown is "ignore", the row_indices and
    # col_indices corresponding to the unknown categorical feature are ignored.
    mask = (X < self.n_values_).ravel()
    if np.any(~mask):
        if self.handle_unknown not in ["error", "ignore"]:
            raise ValueError(
                "handle_unknown should be either error or "
                "unknown got %s" % self.handle_unknown
            )
        if self.handle_unknown == "error":
            raise ValueError(
                "unknown categorical feature present %s during transform." % X[~mask]
            )

    column_indices = (X + indices[:-1]).ravel()[mask]
    row_indices = np.repeat(np.arange(n_samples, dtype=np.int32), n_features)[mask]
    data = np.ones(np.sum(mask))
    out = sparse.coo_matrix(
        (data, (row_indices, column_indices)),
        shape=(n_samples, indices[-1]),
        dtype=self.dtype,
    ).tocsr()
    if self.n_values == "auto":
        out = out[:, self.active_features_]

    return out if self.sparse else out.toarray()


# Traceback (AssertionError)
======================================================================
FAIL: Tests that class_weight and sample_weight are multiplicative
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/buildd/scikit-learn-0.16.0~b1+git1-gab4d07d/debian/python-sklearn/usr/lib/python2.7/dist-packages/sklearn/linear_model/tests/test_sgd.py", line 633, in test_weights_multiplied
assert_array_equal(clf1.coef_, clf2.coef_)
File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 718, in assert_array_equal
verbose=verbose, header='Arrays are not equal')
File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 644, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Arrays are not equal

(mismatch 16.6666666667%)
x: array([[-0.34681637, -0.32240913, -0.31335029,  0.34920789,  0.3658206 ,
0.38752489]])
y: array([[-0.34681637, -0.32240913, -0.31335029,  0.34920789,  0.3658206 ,
0.38752489]])

# Fixed code
def _transform(self, X):
    """Assumes X contains only categorical features."""
    X = check_array(X, dtype=np.int)
    if np.any(X < 0):
        raise ValueError("X needs to contain only non-negative integers.")
    n_samples, n_features = X.shape

    indices = self.feature_indices_
    if n_features != indices.shape[0] - 1:
        raise ValueError(
            "X has different shape than during fitting."
            " Expected %d, got %d." % (indices.shape[0] - 1, n_features)
        )

    # We use only those catgorical features of X that are known using fit.
    # i.e lesser than n_values_ using mask.
    # This means, if self.handle_unknown is "ignore", the row_indices and
    # col_indices corresponding to the unknown categorical feature are
    # ignored.
    mask = (X < self.n_values_).ravel()
    if np.any(~mask):
        if self.handle_unknown not in ["error", "ignore"]:
            raise ValueError(
                "handle_unknown should be either error or "
                "unknown got %s" % self.handle_unknown
            )
        if self.handle_unknown == "error":
            raise ValueError(
                "unknown categorical feature present %s during transform." % X[~mask]
            )

    column_indices = (X + indices[:-1]).ravel()[mask]
    row_indices = np.repeat(np.arange(n_samples, dtype=np.int32), n_features)[mask]
    data = np.ones(np.sum(mask))
    out = sparse.coo_matrix(
        (data, (row_indices, column_indices)),
        shape=(n_samples, indices[-1]),
        dtype=self.dtype,
    ).tocsr()
    if self.n_values == "auto":
        out = out[:, self.active_features_]

    return out if self.sparse else out.toarray()