Skip to content

Commit 4aac610

Browse files
GaelVaroquauxogrisel
authored andcommitted
TST: Fix warnings in np 1.9
These break our tests
1 parent 5cd2da2 commit 4aac610

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

sklearn/cluster/tests/test_hierarchical.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ def test_ward_agglomeration():
209209
assert_warns(DeprecationWarning, WardAgglomeration)
210210
with warnings.catch_warnings(record=True) as warning_list:
211211
warnings.simplefilter("always", DeprecationWarning)
212+
if hasattr(np, 'VisibleDeprecationWarning'):
213+
# Let's not catch the numpy internal DeprecationWarnings
214+
warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
212215
ward = WardAgglomeration(n_clusters=5, connectivity=connectivity)
213216
ward.fit(X)
214217
assert_equal(len(warning_list), 1)

sklearn/utils/fixes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import numpy as np
1616
import scipy.sparse as sp
1717

18+
from .testing import ignore_warnings
1819

1920
np_version = []
2021
for x in np.__version__.split('.'):
@@ -102,7 +103,10 @@ def astype(array, dtype, copy=True):
102103

103104

104105
try:
105-
sp.csr_matrix([1.0, 2.0, 3.0]).max(axis=0)
106+
with ignore_warnings():
107+
# Don't raise the numpy deprecation warnings that appear in
108+
# 1.9
109+
sp.csr_matrix([1.0, 2.0, 3.0]).max(axis=0)
106110
except (TypeError, AttributeError):
107111
# in scipy < 14.0, sparse matrix min/max doesn't accept an `axis` argument
108112
# the following code is taken from the scipy 0.14 codebase

sklearn/utils/testing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ def assert_warns_message(warning_class, message, func, *args, **kw):
193193
with warnings.catch_warnings(record=True) as w:
194194
# Cause all warnings to always be triggered.
195195
warnings.simplefilter("always")
196+
if hasattr(np, 'VisibleDeprecationWarning'):
197+
# Let's not catch the numpy internal DeprecationWarnings
198+
warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
196199
# Trigger a warning.
197200
result = func(*args, **kw)
198201
# Verify some things

0 commit comments

Comments
 (0)