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

small deconvolution bug fix #272

Merged
merged 1 commit into from
Nov 22, 2023
Merged

Conversation

jacksonjacobs1
Copy link
Collaborator

No description provided.

@jacksonjacobs1 jacksonjacobs1 merged commit 8943838 into master Nov 22, 2023
@jacksonjacobs1 jacksonjacobs1 deleted the fix_classification_module branch November 22, 2023 15:53

if stain_matrix == "":
if stain_matrix is None:
Copy link
Owner

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

Copy link
Collaborator Author

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()

Copy link
Owner

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 : )

Copy link
Collaborator Author

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?

Copy link
Owner

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!

Copy link
Collaborator Author

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

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.

2 participants