Repository: scikit-learn/scikit-learn
File: sklearn/preprocessing/_label.py (Python)

Code before:
            )
        )
        data = xp.full_like(indices, pos_label)

        # Fall back to NumPy namespace to construct the sparse matrix of one-hot labels
        Y = sp.csr_matrix(
            (
                _convert_to_numpy(data, xp=xp),
                _convert_to_numpy(indices, xp=xp),
                _convert_to_numpy(indptr, xp=xp),
            ),
            shape=(n_samples, n_classes),
        )

        if not sparse_output:
            Y = xp.asarray(Y.toarray(), device=device_)

    elif y_type == "multilabel-indicator":
        if sparse_output:
            Y = sp.csr_matrix(y)
            if pos_label != 1:
                data = xp.full_like(Y.data, pos_label)
                Y.data = data

        else:
            if sp.issparse(y):
                y = y.toarray()

            Y = xp.asarray(y, device=device_, copy=True)
            if pos_label != 1:
                Y[Y != 0] = pos_label

    else:
        raise ValueError(
            "%s target data is not supported with label binarization" % y_type
        )

    if not sparse_output:
        if neg_label != 0:
            Y[Y == 0] = neg_label

        if pos_switch:
            Y[Y == pos_label] = 0

        Y = xp.astype(Y, int_dtype_)
    else:
        Y.data = Y.data.astype(int, copy=False)

    # preserve label ordering
    if xp.any(classes != sorted_class):
        indices = xp.searchsorted(sorted_class, classes)

Review comment (suggestion):
Just a suggestion to remove the additional newline before the `else` part
```suggestion
        if sparse_output:
            Y = sp.csr_matrix(y)
            if pos_label != 1:
                data = xp.full_like(Y.data, pos_label)
                Y.data = data
        else:
            if sp.issparse(y):
                y = y.toarray()
```

Code after:
            )
        )
        data = xp.full_like(indices, pos_label)

        # Use NumPy to construct the sparse matrix of one-hot labels
        Y = sp.csr_matrix(
            (
                _convert_to_numpy(data, xp=xp),
                _convert_to_numpy(indices, xp=xp),
                _convert_to_numpy(indptr, xp=xp),
            ),
            shape=(n_samples, n_classes),
        )

        if not sparse_output:
            Y = xp.asarray(Y.toarray(), device=device_)

    elif y_type == "multilabel-indicator":
        if sparse_output:
            Y = sp.csr_matrix(y)
            if pos_label != 1:
                data = xp.full_like(Y.data, pos_label)
                Y.data = data
        else:
            if sp.issparse(y):
                y = y.toarray()

            Y = xp.asarray(y, device=device_, copy=True)
            if pos_label != 1:
                Y[Y != 0] = pos_label

    else:
        raise ValueError(
            "%s target data is not supported with label binarization" % y_type
        )

    if not sparse_output:
        if neg_label != 0:
            Y[Y == 0] = neg_label

        if pos_switch:
            Y[Y == pos_label] = 0

        Y = xp.astype(Y, int_dtype_, copy=False)
    else:
        Y.data = Y.data.astype(int, copy=False)

    # preserve label ordering
    if xp.any(classes != sorted_class):
        indices = xp.searchsorted(sorted_class, classes)
        Y = Y[:, indices]