`warnings.warn` function in the conventional `fit` method in `sklearn.cluster._spectral` raises a non-descriptive `TypeError`

### Describe the bug

I was emulating `GridSearch` methodology on fine-tuning `sklearn.cluster.SpectralClustering` with python `for` loops and encountered the error mentioned in the issue topic. This is weird because the error points to the call of `warnings.warn` from `cpython` (built-in). 

I tested the built-in function such that I run:
```python
warnings.warn(
    "The spectral clustering API has changed. ``fit``"
    "now constructs an affinity matrix from data. To use"
    " a custom affinity matrix, "
    "set ``affinity=precomputed``."
)
```
and it put out a warning conventionally acceptable. 

Hence, I have no idea why the error pointing to `warn` is raised instead of the warning itself or instead of the actual error while running the algorithm is traced and displayed. 

### Steps/Code to Reproduce

```python
from sklearn.cluster import SpectralClustering
from numpy import array

X = array([[ 1, 0, 1, 103, 1,   1,   1,   1, 1, 1, 1, 1, 9],
           [ 0, 0, 1,   1, 1,   1,   0,   0, 0, 1, 1, 1, 1],
           [ 1, 0, 1,   0, 1,   1, 478, 478, 0, 1, 1, 1, 1],
           [ 1, 0, 1,  30, 1,   1,   5,   5, 0, 1, 1, 1, 1],
           [ 0, 0, 1,   0, 1,   0,   1,   0, 1, 0, 4, 1, 1],
           [ 0, 0, 1,   1, 1,   0,   1,   0, 1, 0, 5, 1, 1],
           [ 0, 0, 1,   1, 1,   1,   0,   0, 0, 1, 1, 1, 1],
           [ 0, 0, 1,   5, 1,   1, 355, 177, 0, 1, 1, 1, 1],
           [ 0, 0, 1,   1, 1,   0,   1,   0, 1, 0, 6, 1, 1],
           [ 0, 0, 1,   1, 1,   0,   1,   1, 1, 0, 6, 6, 1],
           [ 0, 0, 1,   1, 1, 123,   1,   1, 1, 0, 2, 2, 1],
           [ 0, 0, 1,   1, 1,   1,   1,   1, 1, 1, 1, 1, 1],
           [ 0, 0, 1,   1, 1,   1,   0,   1, 0, 1, 1, 2, 1]],
          dtype=float)
    # sampled from actual dataset shaped `(2833, 532)`

clusterer = SpectralClustering(n_clusters=2,
                               eigen_solver='arpack',
                               random_state=42,
                               affinity='nearest_neighbors',
                               degree=2)

clusterer.fit(X)
```

Although the above reproducible codes involving `X.shape==(13, 13)`, the `.fit` sometimes works fine without encountering the error for extremely small varieties of sampling to `X.shape==(n_samples >= n_attributes, n_attributes)`.

### Expected Results

- A specific indication of the actual cause of the error is included in error traceback; or
- An alternative process was introduced in the module to work around the initial error.

### Actual Results

```python
------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [156], in <cell line: 24>()
      4 X = array([[ 1, 0, 1, 103, 1,   1,   1,   1, 1, 1, 1, 1, 9],
      5            [ 0, 0, 1,   1, 1,   1,   0,   0, 0, 1, 1, 1, 1],
      6            [ 1, 0, 1,   0, 1,   1, 478, 478, 0, 1, 1, 1, 1],
   (...)
     16            [ 0, 0, 1,   1, 1,   1,   0,   1, 0, 1, 1, 2, 1]],
     17           dtype=float)
     19 clusterer = SpectralClustering(n_clusters=2,
     20                                eigen_solver='arpack',
     21                                random_state=42,
     22                                affinity='nearest_neighbors',
     23                                degree=2)
---> 24 clusterer.fit(X)

File /opt/conda/lib/python3.9/site-packages/sklearn/cluster/_spectral.py:658, in SpectralClustering.fit(self, X, y)
    653 allow_squared = self.affinity in [
    654     "precomputed",
    655     "precomputed_nearest_neighbors",
    656 ]
    657 if X.shape[0] == X.shape[1] and not allow_squared:
--> 658     warnings.warn(
    659         "The spectral clustering API has changed. ``fit``"
    660         "now constructs an affinity matrix from data. To use"
    661         " a custom affinity matrix, "
    662         "set ``affinity=precomputed``."
    663     )
    665 check_scalar(
    666     self.n_clusters,
    667     "n_clusters",
   (...)
    670     include_boundaries="left",
    671 )
    673 check_scalar(
    674     self.n_init,
    675     "n_init",
   (...)
    678     include_boundaries="left",
    679 )

TypeError: issubclass() arg 2 must be a class or tuple of classes
```

### Versions

```shell
System:
    python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59)  [GCC 10.3.0]
executable: /opt/conda/bin/python
   machine: Linux-4.14.281-212.502.amzn2.x86_64-x86_64-with-glibc2.31

Python dependencies:
      sklearn: 1.1.1
          pip: 22.1.2
   setuptools: 59.8.0
        numpy: 1.22.4
        scipy: 1.8.1
       Cython: None
       pandas: 1.4.2
   matplotlib: 3.5.2
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /opt/conda/lib/libopenblasp-r0.3.20.so
        version: 0.3.20
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4

       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /opt/conda/lib/libgomp.so.1.0.0
        version: None
    num_threads: 4
```

COMMENT:
> @azhar-ah-axiata out of curiosity could you post the content of `warnings.filters`?

Sure, here it is, @lesteve:
```python
[('ignore',
  re.compile(r'A true SSLContext object is not available.*',
             re.IGNORECASE|re.UNICODE),
  urllib3.exceptions.InsecurePlatformWarning,
  re.compile(r'.*urllib3\.util\.ssl_', re.UNICODE),
  0),
 ('ignore', None, sklearn.exceptions.ConvergenceWarning, None, 0),
 ('always', None, scipy.special._sf_error.SpecialFunctionWarning, None, 0),
 ('ignore',
  re.compile(r'the matrix subclass is not the recommended way',
             re.IGNORECASE|re.UNICODE),
  Warning,
  None,
  0),
 ('ignore',
  re.compile(r'numpy.ndarray size changed', re.IGNORECASE|re.UNICODE),
  Warning,
  None,
  0),
 ('ignore',
  re.compile(r'numpy.ufunc size changed', re.IGNORECASE|re.UNICODE),
  Warning,
  None,
  0),
 ('ignore',
  re.compile(r'numpy.dtype size changed', re.IGNORECASE|re.UNICODE),
  Warning,
  None,
  0),
 ('always', None, numpy.RankWarning, None, 0),
 ('error', None, IPython.core.completer.ProvisionalCompleterWarning, None, 0),
 ('default', None, DeprecationWarning, '__main__', 0),
 ('ignore', None, DeprecationWarning, None, 0),
 ('ignore', None, PendingDeprecationWarning, None, 0),
 ('ignore', None, ImportWarning, None, 0),
 ('ignore', None, ResourceWarning, None, 0),
 ('always', None, urllib3.exceptions.SecurityWarning, None, 0),
 ('default', None, urllib3.exceptions.SubjectAltNameWarning, None, 0),
 ('default', None, urllib3.exceptions.InsecurePlatformWarning, None, 0),
 ('default', None, urllib3.exceptions.SNIMissingWarning, None, 0)]
```

> Additional things I would try I were you:
> 
> * does `warnings.warn('some warning')` give the same error without using scikit-learn?

Yup. I've mentioned this in the initial comment:
>I tested the built-in function such that I run:
>```python
> warnings.warn(
>    "The spectral clustering API has changed. ``fit``"
>    "now constructs an affinity matrix from data. To use"
>    " a custom affinity matrix, "
>    "set ``affinity=precomputed``."
>)
>```
>and it put out a warning conventionally acceptable.

which is referring to this output:
```python
/tmp/ipykernel_185/1351982882.py:2: UserWarning: The spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.
  warnings.warn(
```

> * do some package tweak the warnings filters in a weird way at import time? If so, you should probably open an issue in their issue tracker, because it creates quite a confusing error message as you witnessed ...

The only filtering I did is
```python
import warnings
from sklearn.exceptions import ConvergenceWarning
warnings.simplefilter('ignore', ConvergenceWarning)
```

and this suggestion
> * does `warnings.resetwarnings()` before issuing the first warning fix it?

apparently fixed the issue. My clusterer object is now able to `.fit` just fine.

Labels: Bug, Needs Triage