| 27 | """TransformerMixin plus some helpers.""" |
| 28 | |
| 29 | def _check_data( |
| 30 | self, |
| 31 | epochs_data, |
| 32 | *, |
| 33 | y=None, |
| 34 | atleast_3d=True, |
| 35 | fit=False, |
| 36 | return_y=False, |
| 37 | multi_output=False, |
| 38 | check_n_features=True, |
| 39 | ): |
| 40 | # Sklearn calls asarray under the hood which works, but elsewhere they check for |
| 41 | # __len__ then look at the size of obj[0]... which is an epoch of shape (1, ...) |
| 42 | # rather than what they expect (shape (...)). So we explicitly get the NumPy |
| 43 | # array to make everyone happy. |
| 44 | if isinstance(epochs_data, BaseEpochs): |
| 45 | epochs_data = epochs_data.get_data(copy=False) |
| 46 | kwargs = dict(dtype=np.float64, allow_nd=True, order="C") |
| 47 | if check_version("sklearn", "1.5"): # TODO VERSION sklearn 1.5+ |
| 48 | kwargs["force_writeable"] = True |
| 49 | if hasattr(self, "n_features_in_") and check_n_features: |
| 50 | if y is None: |
| 51 | epochs_data = validate_data( |
| 52 | self, |
| 53 | epochs_data, |
| 54 | **kwargs, |
| 55 | reset=fit, |
| 56 | ) |
| 57 | else: |
| 58 | epochs_data, y = validate_data( |
| 59 | self, |
| 60 | epochs_data, |
| 61 | y, |
| 62 | **kwargs, |
| 63 | reset=fit, |
| 64 | ) |
| 65 | elif y is None: |
| 66 | epochs_data = check_array(epochs_data, **kwargs) |
| 67 | else: |
| 68 | epochs_data, y = check_X_y( |
| 69 | X=epochs_data, y=y, multi_output=multi_output, **kwargs |
| 70 | ) |
| 71 | if fit: |
| 72 | self.n_features_in_ = epochs_data.shape[1] |
| 73 | if atleast_3d: |
| 74 | epochs_data = np.atleast_3d(epochs_data) |
| 75 | return (epochs_data, y) if return_y else epochs_data |
| 76 | |
| 77 | |
| 78 | class _ConstantScaler: |