-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
ENH: stats: Add nan_policy to zmap. #13166
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
Conversation
The change moves the zscore code to zmap, with the obvious change at the end to compute the z-scores for `scores`. zscore is now just a one-liner that calls zmap. Closes scipygh-12403.
mdhaber
left a comment
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.
Looks fine assuming the original code was correct, but I have a question about the ddof parameter - it's not used when nan_policy is omit.
import numpy as np
from scipy.stats import zmap
a = [0.5, 2.0, 2.5, 3]
b = [0, 1, 2, 3, 4]
r1 = zmap(a, b)
r2 = zmap(a, b, ddof = -1)
a = [0.5, 2.0, 2.5, 3, np.nan]
b = [0, 1, 2, 3, 4, np.nan]
r3 = zmap(a, b, nan_policy='omit')
r4 = zmap(a, b, ddof = -1, nan_policy='omit')
print(np.allclose(r1, r3[:-1]))
print(np.allclose(r2, r4[:-1]))
|
Thanks for catching that bug, @mdhaber. I pushed an update with a fix and new tests. |
| [-0.7071067811865476, 0, 0.7071067811865476]),] | ||
| ) | ||
| def test_zmap(self, x, y, expected): | ||
| z = stats.zmap(x, y) |
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.
Personally, I'd remove expected above and just calculate it here so that it's easier to verify that the numbers are correct.
expected = (x - np.mean(y))/np.std(y)
Or maybe the compromise is to add the formula as a comment.
Or just leave it alone. Just a thought. : )
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.
Updated.
mdhaber
left a comment
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.
LGTM
|
The one failure in Azure job |
|
I added a note about this enhancement to the release notes. |
The change moves the zscore code to zmap, with the obvious
change at the end to compute the z-scores for
scores.zscore is now just a one-liner that calls zmap.
Closes gh-12403.