10
10
from sklearn .utils .testing import assert_warns_message
11
11
from sklearn .exceptions import ConvergenceWarning
12
12
from sklearn .utils .validation import check_X_y
13
-
13
+ try :
14
+ from inverse_covariance import quic
15
+ except ImportError :
16
+ HAS_SKGGM = False
17
+ else :
18
+ HAS_SKGGM = True
14
19
from metric_learn import (LMNN , NCA , LFDA , Covariance , MLKR , MMC ,
15
20
LSML_Supervised , ITML_Supervised , SDML_Supervised ,
16
21
RCA_Supervised , MMC_Supervised , SDML )
17
22
# Import this specially for testing.
18
- from metric_learn ._util import has_installed_skggm
19
23
from metric_learn .constraints import wrap_pairs
20
24
from metric_learn .lmnn import python_LMNN
21
25
@@ -150,7 +154,7 @@ def test_no_twice_same_objective(capsys):
150
154
151
155
class TestSDML (MetricTestCase ):
152
156
153
- @pytest .mark .skipif (has_installed_skggm () ,
157
+ @pytest .mark .skipif (HAS_SKGGM ,
154
158
reason = "The warning will be thrown only if skggm is "
155
159
"not installed." )
156
160
def test_raises_warning_msg_not_installed_skggm (self ):
@@ -174,7 +178,7 @@ def test_raises_warning_msg_not_installed_skggm(self):
174
178
sdml_supervised .fit (X , y )
175
179
assert str (record [0 ].message ) == msg
176
180
177
- @pytest .mark .skipif (not has_installed_skggm () ,
181
+ @pytest .mark .skipif (not HAS_SKGGM ,
178
182
reason = "It's only in the case where skggm is installed"
179
183
"that no warning should be thrown." )
180
184
def test_raises_no_warning_installed_skggm (self ):
@@ -245,7 +249,7 @@ def test_sdml_converges_if_psd(self):
245
249
sdml .fit (pairs , y )
246
250
assert np .isfinite (sdml .get_mahalanobis_matrix ()).all ()
247
251
248
- @pytest .mark .skipif (not has_installed_skggm () ,
252
+ @pytest .mark .skipif (not HAS_SKGGM ,
249
253
reason = "sklearn's graphical_lasso can sometimes not "
250
254
"work on some non SPD problems. We test that "
251
255
"is works only if skggm is installed." )
@@ -258,7 +262,7 @@ def test_sdml_works_on_non_spd_pb_with_skggm(self):
258
262
sdml .fit (X , y )
259
263
260
264
261
- @pytest .mark .skipif (not has_installed_skggm () ,
265
+ @pytest .mark .skipif (not HAS_SKGGM ,
262
266
reason = 'The message should be printed only if skggm is '
263
267
'installed.' )
264
268
def test_verbose_has_installed_skggm_sdml (capsys ):
@@ -273,7 +277,7 @@ def test_verbose_has_installed_skggm_sdml(capsys):
273
277
assert "SDML will use skggm's solver." in out
274
278
275
279
276
- @pytest .mark .skipif (not has_installed_skggm () ,
280
+ @pytest .mark .skipif (not HAS_SKGGM ,
277
281
reason = 'The message should be printed only if skggm is '
278
282
'installed.' )
279
283
def test_verbose_has_installed_skggm_sdml_supervised (capsys ):
0 commit comments