BUG - _most_frequent() uses scipy's mode() throwing IndexError

### Describe the bug

I am getting IndexError and it seems that it has started to happen after the recent release of scipy's latest version. I am using the following code:

As per my understanding the error is orignating from _most_frequent() in _base.py in the sklearn.impute sub-package. Seems that an array is expected but the mode() function from scipy is returning integer. Below is the complete error trace:



### Steps/Code to Reproduce

```python
from sklearn.datasets import load_diabetes
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import train_test_split
from deepchecks.tabular.dataset import Dataset
from sklearn.pipeline import Pipeline
from deepchecks.utils.distribution.preprocessing import ScaledNumerics

diabetes = load_diabetes(return_X_y=False, as_frame=True).frame
train_df, test_df = train_test_split(diabetes, test_size=0.33, random_state=42)
train = Dataset(train_df, label='target', cat_features=['sex'])
test = Dataset(test_df, label='target', cat_features=['sex'])
clf = GradientBoostingRegressor(random_state=0)
simple_model = Pipeline([('scaler', ScaledNumerics(train.cat_features, max_num_categories=10)),
                        ('tree-model', clf)])
simple_model.fit(train.data[train.features], train.data[train.label_name])
```

### Expected Results

No error should be thrown.

### Actual Results

```pytb
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
[~\AppData\Local\Temp\ipykernel_9900\2198734096.py](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/SRDEVL131/Desktop/deepchecks/~/AppData/Local/Temp/ipykernel_9900/2198734096.py) in ()
     15 simple_model = Pipeline([('scaler', ScaledNumerics(train.cat_features, max_num_categories=10)),
     16                         ('tree-model', clf)])
---> 17 simple_model.fit(train.data[train.features], train.data[train.label_name])
     18 # train_ds, test_ds = train, test
     19 # check = SimpleModelComparison(strategy='tree')

[c:\Users\SRDEVL131\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\pipeline.py](file:///C:/Users/SRDEVL131/AppData/Local/Programs/Python/Python311/Lib/site-packages/sklearn/pipeline.py) in fit(self, X, y, **fit_params)
    388         """
    389         fit_params_steps = self._check_fit_params(**fit_params)
--> 390         Xt = self._fit(X, y, **fit_params_steps)
    391         with _print_elapsed_time("Pipeline", self._log_message(len(self.steps) - 1)):
    392             if self._final_estimator != "passthrough":

[c:\Users\SRDEVL131\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\pipeline.py](file:///C:/Users/SRDEVL131/AppData/Local/Programs/Python/Python311/Lib/site-packages/sklearn/pipeline.py) in _fit(self, X, y, **fit_params_steps)
    346                 cloned_transformer = clone(transformer)
    347             # Fit or load from cache the current transformer
--> 348             X, fitted_transformer = fit_transform_one_cached(
    349                 cloned_transformer,
    350                 X,

[c:\Users\SRDEVL131\AppData\Local\Programs\Python\Python311\Lib\site-packages\joblib\memory.py](file:///C:/Users/SRDEVL131/AppData/Local/Programs/Python/Python311/Lib/site-packages/joblib/memory.py) in __call__(self, *args, **kwargs)
    347 
    348     def __call__(self, *args, **kwargs):
--> 349         return self.func(*args, **kwargs)
    350 
    351     def call_and_shelve(self, *args, **kwargs):

[c:\Users\SRDEVL131\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\pipeline.py](file:///C:/Users/SRDEVL131/AppData/Local/Programs/Python/Python311/Lib/site-packages/sklearn/pipeline.py) in _fit_transform_one(transformer, X, y, weight, message_clsname, message, **fit_params)
    891     with _print_elapsed_time(message_clsname, message):
    892         if hasattr(transformer, "fit_transform"):
--> 893             res = transformer.fit_transform(X, y, **fit_params)
    894         else:
    895             res = transformer.fit(X, y, **fit_params).transform(X)

[c:\Users\SRDEVL131\Desktop\deepchecks\deepchecks\utils\distribution\preprocessing.py](file:///C:/Users/SRDEVL131/Desktop/deepchecks/deepchecks/utils/distribution/preprocessing.py) in fit_transform(self, X, y, **fit_params)
    103     def fit_transform(self, X, y=None, **fit_params):
    104         """Fit scaler based on given dataframe and then transform it."""
--> 105         self.fit(X)
    106         return self.transform(X)
    107 

[c:\Users\SRDEVL131\Desktop\deepchecks\deepchecks\utils\distribution\preprocessing.py](file:///C:/Users/SRDEVL131/Desktop/deepchecks/deepchecks/utils/distribution/preprocessing.py) in fit(self, X)
     68         if self.cat_columns:
     69             self.categorical_imputer = SimpleImputer(strategy='most_frequent')
---> 70             self.categorical_imputer.fit(X[self.cat_columns])
     71         if self.not_cat_columns:
     72             self.numeric_imputer = SimpleImputer(strategy='mean')

[c:\Users\SRDEVL131\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\impute\_base.py](file:///C:/Users/SRDEVL131/AppData/Local/Programs/Python/Python311/Lib/site-packages/sklearn/impute/_base.py) in fit(self, X, y)
    356 
    357         else:
--> 358             self.statistics_ = self._dense_fit(
    359                 X, self.strategy, self.missing_values, fill_value
    360             )

[c:\Users\SRDEVL131\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\impute\_base.py](file:///C:/Users/SRDEVL131/AppData/Local/Programs/Python/Python311/Lib/site-packages/sklearn/impute/_base.py) in _dense_fit(self, X, strategy, missing_values, fill_value)
    442                 row_mask = np.logical_not(row_mask).astype(bool)
    443                 row = row[row_mask]
--> 444                 most_frequent[i] = _most_frequent(row, np.nan, 0)
    445 
    446             return most_frequent

[c:\Users\SRDEVL131\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\impute\_base.py](file:///C:/Users/SRDEVL131/AppData/Local/Programs/Python/Python311/Lib/site-packages/sklearn/impute/_base.py) in _most_frequent(array, extra_value, n_repeat)
     48         else:
     49             mode = stats.mode(array)
---> 50             most_frequent_value = mode[0][0]
     51             most_frequent_count = mode[1][0]
     52     else:

IndexError: invalid index to scalar variable.
```

### Versions

```shell
sklearn==1.3.0
scipy==1.11.1
```

COMMENT:
Hey @betatim/@glemaitre,

After debugging more, it seems an issue from a version mismatch from my end. Sorry for the inconvenience caused. Closing the issue.

Labels: Bug, Needs Triage