-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Clean nanops.get_corr_func #33244
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9963916
CLN: Clean nanops.get_corr_func
dsaxton 137dddd
Don't use lambda
dsaxton daa77e2
Merge remote-tracking branch 'upstream/master' into get-corr
dsaxton d879608
Merge remote-tracking branch 'upstream/master' into get-corr
dsaxton f8b3617
No else
dsaxton 12a91a2
Merge remote-tracking branch 'upstream/master' into get-corr
dsaxton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1332,30 +1332,33 @@ def nancorr( | |
|
||
|
||
def get_corr_func(method): | ||
if method in ["kendall", "spearman"]: | ||
from scipy.stats import kendalltau, spearmanr | ||
elif method in ["pearson"]: | ||
pass | ||
elif callable(method): | ||
return method | ||
else: | ||
raise ValueError( | ||
f"Unknown method '{method}', expected one of 'kendall', 'spearman'" | ||
) | ||
if method == "kendall": | ||
from scipy.stats import kendalltau | ||
|
||
def func(a, b): | ||
return kendalltau(a, b)[0] | ||
|
||
def _pearson(a, b): | ||
return np.corrcoef(a, b)[0, 1] | ||
return func | ||
elif method == "spearman": | ||
from scipy.stats import spearmanr | ||
|
||
def _kendall(a, b): | ||
# kendallttau returns a tuple of the tau statistic and pvalue | ||
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. is this comment worth retaining? 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. Might as well, should we also have a comment for spearmanr and np.corrcoef? |
||
rs = kendalltau(a, b) | ||
return rs[0] | ||
def func(a, b): | ||
return spearmanr(a, b)[0] | ||
|
||
def _spearman(a, b): | ||
return spearmanr(a, b)[0] | ||
return func | ||
elif method == "pearson": | ||
|
||
_cor_methods = {"pearson": _pearson, "kendall": _kendall, "spearman": _spearman} | ||
return _cor_methods[method] | ||
def func(a, b): | ||
return np.corrcoef(a, b)[0, 1] | ||
|
||
return func | ||
elif callable(method): | ||
return method | ||
|
||
raise ValueError( | ||
f"Unknown method '{method}', expected one of " | ||
"'kendall', 'spearman', 'pearson', or callable" | ||
) | ||
|
||
|
||
@disallow("M8", "m8") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
i would make all of these lambda, e.g.(for all 3 cases)
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.
hah, i asked for these to be changed from lambda to non-lambdas for nicer tracebacks
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.
oh really it does? hmm, ok, then that's fine