Skip to content

Commit

Permalink
ENH do not fail the test reslying on numpy div 0 warnings if those ar…
Browse files Browse the repository at this point in the history
…e not spit out by numpy in general
  • Loading branch information
yarikoptic committed Jul 4, 2012
1 parent 5ec4a0a commit 37b440e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sklearn/feature_extraction/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sklearn.svm import LinearSVC

import numpy as np
from nose import SkipTest
from nose.tools import assert_equal, assert_equals, \
assert_false, assert_not_equal, assert_true
from numpy.testing import assert_array_almost_equal
Expand Down Expand Up @@ -260,8 +261,15 @@ def test_tfidf_no_smoothing():
[1, 0, 0]]
tr = TfidfTransformer(smooth_idf=False, norm='l2')

# First we need to verify that numpy here provides div 0 warnings
with warnings.catch_warnings(record=True) as w:
_ = 1. / np.array([0.])
numpy_provides_div0_warning = len(w) == 1

with warnings.catch_warnings(record=True) as w:
tfidf = tr.fit_transform(X).toarray()
if not numpy_provides_div0_warning:
raise SkipTest("Numpy does not provide div 0 warnings.")
assert_equal(len(w), 1)
# For Python 3 compatibility
if hasattr(w[0].message, 'args'):
Expand Down

0 comments on commit 37b440e

Please sign in to comment.