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
Added a check for empty array in _shared.utils.py #2364
Added a check for empty array in _shared.utils.py #2364
Conversation
@tseclaudia Hi! Thank for catching this up! |
Current coverage is 90.60% (diff: 27.27%)@@ master #2364 diff @@
==========================================
Files 305 305
Lines 21582 21605 +23
Methods 0 0
Messages 0 0
Branches 1853 1857 +4
==========================================
+ Hits 19563 19575 +12
- Misses 1665 1674 +9
- Partials 354 356 +2
|
… array is passed into features.local_binary_pattern
@tseclaudia fair enough, sorry. OK, then I'd like to ask you to add a test to |
try: | ||
z = np.random.random(200**2).reshape((200, 200)) | ||
x = z[10:30, 30:10] | ||
assert_nD(x, 2) |
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.
There is no need to use try/except
here. Just use numpy.testing.assert_raises
, i.e.
from numpy.testing import assert_raises
...
assert_raises(ValueError, assert_nD, x, 2)
# z = np.random.random(200**2).reshape((200, 200)) | ||
# x = z[10:30, 30:10] | ||
# lbp = feature.local_binary_pattern(x, 8, 1, 'uniform') | ||
try: |
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.
Same here.
@@ -228,6 +229,22 @@ def test_uniform(self): | |||
[2, 9, 0, 8, 1, 2]]) | |||
np.testing.assert_array_equal(lbp, ref) | |||
|
|||
def test_empty(self): | |||
# with unittest.TestCase.assertRaises(ValueError): |
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.
Remove the comments.
@@ -147,7 +147,7 @@ def safe_as_int(val, atol=1e-3): | |||
|
|||
def assert_nD(array, ndim, arg_name='image'): | |||
""" | |||
Verify an array meets the desired ndims. | |||
Verify an array meets the desired ndims and array isn't empty. |
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.
Did you accidentally remove the proposed fix?
|
||
|
||
def test_assert_nD(): | ||
try: |
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.
Remove try:
try: | ||
z = np.random.random(200**2).reshape((200, 200)) | ||
x = z[10:30, 30:10] | ||
assert_raises(ValueError, assert_nDx, 2) |
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.
-> assert_raises(ValueError, assert_nD, x, 2)
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.
It looks like the coverage has decreased because the new test is incorrect...?
@@ -1,7 +1,16 @@ | |||
from skimage._shared.utils import copy_func | |||
from skimage._shared.utils import (copy_func, |
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.
one line: from skimage._shared.utils import copy_func, assert_nD
def test_assert_nD(): | ||
z = np.random.random(200**2).reshape((200, 200)) | ||
x = z[10:30, 30:10] | ||
assert_raises(ValueError, assert_nD, 2) |
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.
Should this be assert_nD, x, 2
?
Thanks @tseclaudia! |
Description
Addresses Issue #2053