Skip to content

Commit 09d19ef

Browse files
committed
MAINT: Use MNE optional import for JAMICA
1 parent 02740c6 commit 09d19ef

2 files changed

Lines changed: 5 additions & 18 deletions

File tree

‎mne/preprocessing/ica.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
_pl,
7373
_reject_data_segments,
7474
_require_version,
75+
_soft_import,
7576
_validate_type,
7677
check_fname,
7778
check_random_state,
@@ -684,9 +685,6 @@ def fit(
684685
for method, mod in req_map.items():
685686
if self.method == method:
686687
_require_version(mod, f"use method={repr(method)}")
687-
if self.method == "jamica":
688-
_require_version("jamica", "use method='jamica'", "0.3.0")
689-
690688
_validate_type(inst, (BaseRaw, BaseEpochs), "inst", "Raw or Epochs")
691689

692690
if np.isclose(inst.info["highpass"], 0.0):
@@ -1017,9 +1015,11 @@ def _fit(self, data, fit_type):
10171015
self.n_iter_ = n_iter + 1 # picard() starts counting at 0
10181016
del _, n_iter
10191017
elif self.method == "jamica":
1020-
from jamica import amica
1018+
jamica = _soft_import(
1019+
"jamica", "fitting ICA with method='jamica'", min_version="0.3.0"
1020+
)
10211021

1022-
_, W, _, n_iter = amica(
1022+
_, W, _, n_iter = jamica.amica(
10231023
data[:, sel].T,
10241024
whiten=False,
10251025
return_n_iter=True,

‎mne/preprocessing/tests/test_ica.py‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,6 @@ def test_ica_simple(method):
184184
assert amari_distance < 0.1
185185

186186

187-
def test_ica_jamica_missing_dependency(monkeypatch):
188-
"""Test the optional JAMICA dependency error."""
189-
raw = RawArray(np.zeros((2, 10)), create_info(2, 100.0, "mag"), verbose=False)
190-
monkeypatch.setattr(
191-
"mne.utils.check.import_module", MagicMock(side_effect=ImportError)
192-
)
193-
with pytest.raises(
194-
ImportError,
195-
match=r"jamica package \(version >= 0\.3\.0\).*method='jamica'",
196-
):
197-
ICA(n_components=2, method="jamica").fit(raw)
198-
199-
200187
def test_ica_jamica_multimodel_error():
201188
"""Test that JAMICA's single-model error propagates through ICA."""
202189
pytest.importorskip("jamica", minversion="0.3.0")

0 commit comments

Comments
 (0)