-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
TST: Suppressed warnings #7099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TST: Suppressed warnings #7099
Changes from 1 commit
29a45ef
968507b
86b0a5e
78d7cc4
c1ddf84
308161c
9bf7d14
f078cb4
2e86117
b831444
61694be
20ea3a2
514d136
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Comment mentions a speedup, but it seems unsure why it should be there. Instead use an error state in divide_by_count. Some extra complex warnings had to be ignored (but those seemed correct)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import numpy as np | ||
from numpy.testing import ( | ||
run_module_suite, TestCase, assert_, assert_equal, assert_almost_equal, | ||
assert_warns, assert_no_warnings, assert_raises, assert_array_equal | ||
assert_no_warnings, assert_raises, assert_array_equal, suppress_warnings | ||
) | ||
|
||
|
||
|
@@ -317,26 +317,30 @@ def test_dtype_from_dtype(self): | |
codes = 'efdgFDG' | ||
for nf, rf in zip(self.nanfuncs, self.stdfuncs): | ||
for c in codes: | ||
tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type | ||
res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type | ||
assert_(res is tgt) | ||
# scalar case | ||
tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type | ||
res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type | ||
assert_(res is tgt) | ||
with suppress_warnings() as sup: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this was not needed before. I assume that it is needed now because the lower level warning is no longer caught. Is that what we want? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we used to have a I am not quite sure what you mean here, sorry. I guess the outer level does not catch the warning anymore, you could argue about it, but this is very explicit (i.e. someone writing a new test realizes there is a warning going on). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, it is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe open an issue for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the correct fix. The class is a mixin, and fails for one specific function, so suppressing the warning for all functions is over kill. We should either fix the test or fix the function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe I will add a bit non-pretty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the test specific with this hack (also fixed the other things like removing the full stuff and used more suppress_warnings, though for now only in the nanfunc tests.... Probably lots of places where we could do it more and I am willing to work a bit more on it later. But for the sake of keeping this not too long, maybe it is better to wait. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did not have a quick idea how to fix the spurious warning bug in a very "obvious" way, but can think about it some more.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the quick hack was the first thing to occur to me also. Not pretty, but at least it is documented. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, as long as we have a good idea as to what needs fixing, I'd like to get this in as soon as possible. |
||
sup.filter(np.ComplexWarning) | ||
tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type | ||
res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type | ||
assert_(res is tgt) | ||
# scalar case | ||
tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type | ||
res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type | ||
assert_(res is tgt) | ||
|
||
def test_dtype_from_char(self): | ||
mat = np.eye(3) | ||
codes = 'efdgFDG' | ||
for nf, rf in zip(self.nanfuncs, self.stdfuncs): | ||
for c in codes: | ||
tgt = rf(mat, dtype=c, axis=1).dtype.type | ||
res = nf(mat, dtype=c, axis=1).dtype.type | ||
assert_(res is tgt) | ||
# scalar case | ||
tgt = rf(mat, dtype=c, axis=None).dtype.type | ||
res = nf(mat, dtype=c, axis=None).dtype.type | ||
assert_(res is tgt) | ||
with suppress_warnings() as sup: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment. |
||
sup.filter(np.ComplexWarning) | ||
tgt = rf(mat, dtype=c, axis=1).dtype.type | ||
res = nf(mat, dtype=c, axis=1).dtype.type | ||
assert_(res is tgt) | ||
# scalar case | ||
tgt = rf(mat, dtype=c, axis=None).dtype.type | ||
res = nf(mat, dtype=c, axis=None).dtype.type | ||
assert_(res is tgt) | ||
|
||
def test_dtype_from_input(self): | ||
codes = 'efdgFDG' | ||
|
@@ -524,16 +528,16 @@ def test_ddof_too_big(self): | |
dsize = [len(d) for d in _rdat] | ||
for nf, rf in zip(nanfuncs, stdfuncs): | ||
for ddof in range(5): | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter('always') | ||
with suppress_warnings() as sup: | ||
sup.record(RuntimeWarning) | ||
sup.filter(np.ComplexWarning) | ||
tgt = [ddof >= d for d in dsize] | ||
res = nf(_ndat, axis=1, ddof=ddof) | ||
assert_equal(np.isnan(res), tgt) | ||
if any(tgt): | ||
assert_(len(w) == 1) | ||
assert_(issubclass(w[0].category, RuntimeWarning)) | ||
assert_(len(sup.log) == 1) | ||
else: | ||
assert_(len(w) == 0) | ||
assert_(len(sup.log) == 0) | ||
|
||
def test_allnans(self): | ||
mat = np.array([np.nan]*9).reshape(3, 3) | ||
|
@@ -642,22 +646,20 @@ def test_result_values(self): | |
def test_allnans(self): | ||
mat = np.array([np.nan]*9).reshape(3, 3) | ||
for axis in [None, 0, 1]: | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter('always') | ||
warnings.simplefilter('ignore', FutureWarning) | ||
with suppress_warnings() as sup: | ||
sup.record(RuntimeWarning) | ||
|
||
assert_(np.isnan(np.nanmedian(mat, axis=axis)).all()) | ||
if axis is None: | ||
assert_(len(w) == 1) | ||
assert_(len(sup.log) == 1) | ||
else: | ||
assert_(len(w) == 3) | ||
assert_(issubclass(w[0].category, RuntimeWarning)) | ||
assert_(len(sup.log) == 3) | ||
# Check scalar | ||
assert_(np.isnan(np.nanmedian(np.nan))) | ||
if axis is None: | ||
assert_(len(w) == 2) | ||
assert_(len(sup.log) == 2) | ||
else: | ||
assert_(len(w) == 4) | ||
assert_(issubclass(w[0].category, RuntimeWarning)) | ||
assert_(len(sup.log) == 4) | ||
|
||
def test_empty(self): | ||
mat = np.zeros((0, 3)) | ||
|
@@ -686,7 +688,7 @@ def test_extended_axis_invalid(self): | |
|
||
def test_float_special(self): | ||
with warnings.catch_warnings(record=True): | ||
warnings.simplefilter('ignore', RuntimeWarning) | ||
warnings.simplefilter('always', RuntimeWarning) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa, was that a bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I think ignoring this was intended, what changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just avoiding all ignore filters, catch_warnings does not propagate outside so setting it to "always" effectively ignores it. Might be a bit cleaner to ues the new context though. At the beginning I did not always. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. The record was never looked at anyway, so we could probably do without a filter of anysort. However, using |
||
a = np.array([[np.inf, np.nan], [np.nan, np.nan]]) | ||
assert_equal(np.nanmedian(a, axis=0), [np.inf, np.nan]) | ||
assert_equal(np.nanmedian(a, axis=1), [np.inf, np.nan]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't understand why it would speed things up, I somewhat assumed that adding divide=ignore for _divide_by_count does the trick here as well. (same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(had to ignore more complex warnings then, but that seemed right)