Skip to content

Commit

Permalink
On ICA._reset(), set current_fit to "unfitted" (#11139)
Browse files Browse the repository at this point in the history
This is mostly a code health change fixing an internal inconsistency
that I just ran into while working on another feature:

When calling the private `ICA._reset()` method, we forgot to
reset `ICA.current_fit` as well.

This change causes no user-facing alterations.
  • Loading branch information
hoechenberger authored Sep 7, 2022
1 parent 879829e commit b8ba02f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions mne/preprocessing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ class ICA(ContainsMixin):
Attributes
----------
current_fit : str
Flag informing about which data type (raw or epochs) was used for the
fit.
current_fit : 'unfitted' | 'raw' | 'epochs'
Which data type was used for the fit.
ch_names : list-like
Channel names resulting from initial picking.
n_components_ : int
Expand Down Expand Up @@ -682,6 +681,7 @@ def _reset(self):
'pca_mean_', 'n_iter_', 'drop_inds_', 'reject_'):
if hasattr(self, key):
delattr(self, key)
self.current_fit = 'unfitted'

def _fit_raw(self, raw, picks, start, stop, decim, reject, flat, tstep,
reject_by_annotation, verbose):
Expand Down
9 changes: 7 additions & 2 deletions mne/preprocessing/tests/test_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,20 @@ def test_ica_reset(method):
'pca_mean_',
'n_iter_'
)

ica = ICA(n_components=3, method=method, max_iter=1)
assert ica.current_fit == 'unfitted'
with pytest.warns(UserWarning, match='did not converge'):
ica = ICA(
n_components=3, method=method, max_iter=1).fit(raw, picks=picks)
ica.fit(raw, picks=picks)

assert (all(hasattr(ica, attr) for attr in run_time_attrs))
assert ica.labels_ is not None
assert ica.current_fit == 'raw'

ica._reset()
assert (not any(hasattr(ica, attr) for attr in run_time_attrs))
assert ica.labels_ is not None
assert ica.current_fit == 'unfitted'


@requires_sklearn
Expand Down

0 comments on commit b8ba02f

Please sign in to comment.