Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@WarrenWeckesser
Copy link
Member

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.

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.
@WarrenWeckesser WarrenWeckesser added scipy.stats enhancement A new feature or improvement labels Nov 29, 2020
Copy link
Contributor

@mdhaber mdhaber left a 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]))

@WarrenWeckesser
Copy link
Member Author

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)
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Contributor

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@WarrenWeckesser
Copy link
Member Author

The one failure in Azure job scipy.scipy (prerelease_deps_64bit_blas) is unrelated to this PR.

@mdhaber mdhaber merged commit 2f76ff0 into scipy:master Dec 20, 2020
@WarrenWeckesser WarrenWeckesser deleted the zmap branch December 21, 2020 05:02
@WarrenWeckesser WarrenWeckesser added this to the 1.7.0 milestone Dec 21, 2020
@WarrenWeckesser
Copy link
Member Author

I added a note about this enhancement to the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A new feature or improvement scipy.stats

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add nan_policy to stats.zmap

2 participants