Firstly, `setxor1d` is overkill. All you need to ensure there is at most 2 labels is `len(y.data) == 0 or np.ptp(y.data) == 0`.

Secondly, this doesn't work for sparse types without `data` (e.g. DOK), or `lil_matrix` which has a `data` attribute that is an array of lists. Instead you can use:
```python
def is_sparse_and_binary(y):
    if not hasattr(y, 'data') or y.data.dtype.kind == 'O':
        y = y.tocoo()
    return len(y.data) == 0 or np.ptp(y.data) == 0 
```
 (You could use `isinstance(y, scipy.sparse.data._data_matrix)`, but that involves a private class.)