@@ -1332,30 +1332,33 @@ def nancorr(
1332
1332
1333
1333
1334
1334
def get_corr_func (method ):
1335
- if method in ["kendall" , "spearman" ]:
1336
- from scipy .stats import kendalltau , spearmanr
1337
- elif method in ["pearson" ]:
1338
- pass
1339
- elif callable (method ):
1340
- return method
1341
- else :
1342
- raise ValueError (
1343
- f"Unknown method '{ method } ', expected one of 'kendall', 'spearman'"
1344
- )
1335
+ if method == "kendall" :
1336
+ from scipy .stats import kendalltau
1337
+
1338
+ def func (a , b ):
1339
+ return kendalltau (a , b )[0 ]
1345
1340
1346
- def _pearson (a , b ):
1347
- return np .corrcoef (a , b )[0 , 1 ]
1341
+ return func
1342
+ elif method == "spearman" :
1343
+ from scipy .stats import spearmanr
1348
1344
1349
- def _kendall (a , b ):
1350
- # kendallttau returns a tuple of the tau statistic and pvalue
1351
- rs = kendalltau (a , b )
1352
- return rs [0 ]
1345
+ def func (a , b ):
1346
+ return spearmanr (a , b )[0 ]
1353
1347
1354
- def _spearman ( a , b ):
1355
- return spearmanr ( a , b )[ 0 ]
1348
+ return func
1349
+ elif method == "pearson" :
1356
1350
1357
- _cor_methods = {"pearson" : _pearson , "kendall" : _kendall , "spearman" : _spearman }
1358
- return _cor_methods [method ]
1351
+ def func (a , b ):
1352
+ return np .corrcoef (a , b )[0 , 1 ]
1353
+
1354
+ return func
1355
+ elif callable (method ):
1356
+ return method
1357
+
1358
+ raise ValueError (
1359
+ f"Unknown method '{ method } ', expected one of "
1360
+ "'kendall', 'spearman', 'pearson', or callable"
1361
+ )
1359
1362
1360
1363
1361
1364
@disallow ("M8" , "m8" )
0 commit comments