-
Notifications
You must be signed in to change notification settings - Fork 22
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
Util unit tests #261
Util unit tests #261
Conversation
from tools.cell_census_builder.util import array_chunker, is_positive_integral, uricat | ||
|
||
|
||
def test_is_positive_integral() -> 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.
To be pedantic, this method should be called is_nonnegative_integral
since 0 is an accepted value. If that looks better I can make the change.
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.
feel free to improve it!
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 you do this, please also add a test of empty array, e.g.,
assert not is_nonnegative_integral(np.array([], dtype=np.float32))
and equivalent for sparse.
Codecov Report
@@ Coverage Diff @@
## main #261 +/- ##
==========================================
+ Coverage 92.22% 93.52% +1.29%
==========================================
Files 33 34 +1
Lines 1943 2023 +80
==========================================
+ Hits 1792 1892 +100
+ Misses 151 131 -20
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
||
|
||
def test_is_positive_integral() -> None: | ||
X = np.array([1, 2, 3, 4]) |
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.
these result in an array of dtype np.int64. The function only accepts floats (both float32 and float64), although it does not raise an error if the input violates the type signature.
These tests should explicitly create arrays of dtype float32 or float64. Prefer float32 for most tests, as that is what we typically receive.
assert chunked[4].nnz == 19 | ||
|
||
# Other formats are rejected by the method | ||
X = triu(np.ones(100).reshape(10, 10)).tocoo() |
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.
recommend testing this by passing something other than COO (eg., LIL or BSR), as it is fairly likely we will add COO support the the array_chunker at some point. Just change the final call from tocoo()
to tolil()
(or anything other than csr/csc/coo)
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.
couple of change requests. hit me up for a second review when ready.
X = csr_matrix([[1, 2, 3], [4, 5, 6]]) | ||
assert is_nonnegative_integral(X) | ||
|
||
X = csr_matrix([[-1, 2, 3], [4, 5, 6]]) |
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.
these are also int64 - same issue as with ndarray, they need a float dtype to be specified.
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.
Apologies, for some reason I thought scipy.sparse created float matrices by default. Fixing it.
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 more dtype issue on the is_nonnegative_integral
test.
I'm marking as approved, on the assumption you will add those explicit dtypes....
Unit tests for:
is_positive_integral
array_chunker
uricat