OrdinalEncoder not transforming nans as expected.

### Describe the bug

When fitting an OrdinalEncoder with a pandas Series that contains a nan, transforming an array containing only nans fails, even though nan is one of the OrdinalEncoder classes.

This seems similar to this issue https://github.com/scikit-learn/scikit-learn/issues/22628

### Steps/Code to Reproduce

```python
from sklearn import preprocessing
import numpy as np
encoder = preprocessing.OrdinalEncoder()
data = np.array(['cat', 'dog', np.nan, 'fish', 'dog']).reshape(-1, 1)
encoder.fit(data)
only_nan = np.array([np.nan]).reshape(-1, 1)
encoder.transform(only_nan)
```

### Expected Results

Instead of the error, I'd expect the output to be `array([3])`.

### Actual Results

```bash
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rafaelascensao/work/scikit-learn-test/.venv/lib/python3.10/site-packages/sklearn/utils/_set_output.py", line 316, in wrapped
    data_to_wrap = f(self, X, *args, **kwargs)
  File "/Users/rafaelascensao/work/scikit-learn-test/.venv/lib/python3.10/site-packages/sklearn/preprocessing/_encoders.py", line 1578, in transform
    X_int, X_mask = self._transform(
  File "/Users/rafaelascensao/work/scikit-learn-test/.venv/lib/python3.10/site-packages/sklearn/preprocessing/_encoders.py", line 206, in _transform
    diff, valid_mask = _check_unknown(Xi, self.categories_[i], return_mask=True)
  File "/Users/rafaelascensao/work/scikit-learn-test/.venv/lib/python3.10/site-packages/sklearn/utils/_encode.py", line 304, in _check_unknown
    if np.isnan(known_values).any():
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
```

### Versions

```shell
System:
    python: 3.10.11 (main, Aug 22 2024, 14:00:26) [Clang 15.0.0 (clang-1500.3.9.4)]
executable: /Users/rafaelascensao/work/scikit-learn-test/.venv/bin/python
   machine: macOS-15.0.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.5.2
          pip: 24.2
   setuptools: 69.5.1
        numpy: 2.1.3
        scipy: 1.14.1
       Cython: None
       pandas: 2.2.3
   matplotlib: 3.9.2
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 8
         prefix: libomp
       filepath: /Users/rafaelascensao/work/scikit-learn-test/.venv/lib/python3.10/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
```

COMMENT:
The reason is because you provide non-consistent dtype arrays:

```python
In [2]: data.dtype
Out[2]: dtype('<U32')

In [3]: data
Out[3]: 
array([['cat'],
       ['dog'],
       ['nan'],
       ['fish'],
       ['dog']], dtype='<U32')

In [4]: only_nan.dtype
Out[4]: dtype('float64')

In [5]: only_nan
Out[5]: array([[nan]])
```

If you have a consistent dtype, then it works as expected:

```python
In [7]: encoder.transform(only_nan.astype(data.dtype))
Out[7]: array([[3.]])
```

I don't think that we can fix anything here. Or potentially making the conversion ourself but I'm not sure we should do that because this is really implicit.

Labels: Bug, Needs Triage