-
Notifications
You must be signed in to change notification settings - Fork 13
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
ENH: Function to detect sign of a number #14
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def sign_func(value: float) -> float: | ||
return -1 if value < 0 else 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you see in the test suite here that things are failing, saying You might wonder why it works while using You can fix this by adding
Since numpy is only used in your test suite in this PR, it should go in |
||
|
||
from ..feature_sign import sign_func | ||
|
||
|
||
def test_simple_sign_func(): | ||
assert sign_func(-100000.346) == -1 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"value, expected", | ||
[ | ||
(0, 1), | ||
(10000.0, 1), | ||
(-345236.78, -1) | ||
] | ||
) | ||
|
||
def test_sign_func(value: float, expected: float): | ||
sign_val = sign_func(value) | ||
expected = np.sign(value) | ||
assert expected==sign_val |
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's one more thing failing in the "pre-commit" check.
Did you use
pre-commit
when committing your code? It automatically sorts imports and tells you about style issues before it gets to GitHub.The output here:
Tells you that
isort
would have putnumpy
beforepytest
, because they are sorted alphabetically by convention.To fix it, you can do as it says above:
Or manually fix based on what it says, of course. I'm lazy and prefer to have pre-commit take care of it for me, though!