Skip to content
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

Merged

Conversation

tseclaudia
Copy link
Contributor

Description

Addresses Issue #2053

@soupault
Copy link
Member

soupault commented Nov 1, 2016

@tseclaudia Hi! Thank for catching this up!
In order to close #2053 you'll need to address the 2nd part of the issue as well: adding assert_nD to feature.local_binary_pattern. Should also add a simple test which fails on a current master but will be fixed with your patch merged.

@codecov-io
Copy link

codecov-io commented Nov 1, 2016

Current coverage is 90.60% (diff: 27.27%)

Merging #2364 into master will decrease coverage by 0.04%

@@             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   

Powered by Codecov. Last update 3551389...f642de0

@tseclaudia
Copy link
Contributor Author

@soupault Doesn't feature.local_binary_pattern already contain assert_nD which checks that the passed in array meets the desired ndims and isn't an empty array? Does that correctly address the second part of the issue?

… array is passed into features.local_binary_pattern
@soupault
Copy link
Member

soupault commented Nov 1, 2016

@tseclaudia fair enough, sorry. OK, then I'd like to ask you to add a test to _shared/tests/test_utils.py checking if assert_nD raises an error on empty array.
Oh, and, please, follow code style conventions (i.e. wrap at 80th column).

try:
z = np.random.random(200**2).reshape((200, 200))
x = z[10:30, 30:10]
assert_nD(x, 2)
Copy link
Member

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:
Copy link
Member

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):
Copy link
Member

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.
Copy link
Member

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:
Copy link
Member

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)
Copy link
Member

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)

soupault
soupault previously approved these changes Nov 15, 2016
Copy link
Member

@jni jni left a 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,
Copy link
Member

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)
Copy link
Member

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?

@soupault
Copy link
Member

soupault commented Dec 1, 2016

Thanks @tseclaudia!

@soupault soupault merged commit 25fef7f into scikit-image:master Dec 1, 2016
@tseclaudia tseclaudia deleted the check-for-empty-array-in-assert_nD branch December 1, 2016 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants