Skip to content

Commit 3f57ae7

Browse files
ShaharNavehjreback
authored andcommitted
Added 'pearson' to methods list in pandas/core/nanops.py (#30603)
1 parent 6600b5b commit 3f57ae7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pandas/core/nanops.py

+6
Original file line numberDiff line numberDiff line change
@@ -1243,8 +1243,14 @@ def nancorr(a, b, method="pearson", min_periods=None):
12431243
def get_corr_func(method):
12441244
if method in ["kendall", "spearman"]:
12451245
from scipy.stats import kendalltau, spearmanr
1246+
elif method in ["pearson"]:
1247+
pass
12461248
elif callable(method):
12471249
return method
1250+
else:
1251+
raise ValueError(
1252+
f"Unkown method '{method}', expected one of 'kendall', 'spearman'"
1253+
)
12481254

12491255
def _pearson(a, b):
12501256
return np.corrcoef(a, b)[0, 1]

pandas/tests/test_nanops.py

+8
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,14 @@ def test_nancorr_spearman(self):
598598
targ1 = spearmanr(self.arr_float_1d.flat, self.arr_float1_1d.flat)[0]
599599
self.check_nancorr_nancov_1d(nanops.nancorr, targ0, targ1, method="spearman")
600600

601+
@td.skip_if_no_scipy
602+
def test_invalid_method(self):
603+
targ0 = np.corrcoef(self.arr_float_2d, self.arr_float1_2d)[0, 1]
604+
targ1 = np.corrcoef(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0, 1]
605+
msg = "Unkown method 'foo', expected one of 'kendall', 'spearman'"
606+
with pytest.raises(ValueError, match=msg):
607+
self.check_nancorr_nancov_1d(nanops.nancorr, targ0, targ1, method="foo")
608+
601609
def test_nancov(self):
602610
targ0 = np.cov(self.arr_float_2d, self.arr_float1_2d)[0, 1]
603611
targ1 = np.cov(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0, 1]

0 commit comments

Comments
 (0)