-
Notifications
You must be signed in to change notification settings - Fork 107
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
small deconvolution bug fix #272
Conversation
|
||
if stain_matrix == "": | ||
if stain_matrix is None: |
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.
i think this is more pythonic as
if not stain_matrix::
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.
if not stain_matrix:
This line would work if stain_matrix were a python array, but not for an ndarray. That's because numpy uses their own Truthy behavior:
>>> import numpy as np
>>> arr = np.array([1,2,3])
>>> if arr:
... print("something")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
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.
got it, what about this however:
>>> arr = np.array([])
>>> if arr:
... print("something")
...
<stdin>:1: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
should we use arr.size?
>>> if arr.size:
... print("test")
... else:
... print("no")
...
but i guess then this would need to be changed to:
stain_matrix = getattr(sys.modules[__name__], stain, np.array([]))
probably starting to overengineer this : )
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.
Would you consider checking for an empty array more pythonic than "is None"?
I like NoneType here because there's less ambiguity. Otherwise, an empty array could mean the getattr() used the default value OR the stain attribute actually stored an empty array.
Thoughts?
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.
yea, i think you got it. None seems like the better option here!
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.
As well, I think this is the behavior we want, right?
>>> import numpy as np
>>> arr = np.array([])
>>> if arr is None:
... print("array is none")
... else:
... print("array is not none")
...
array is not none
No description provided.