Skip to content

Commit 64f5961

Browse files
fbnrstjreback
authored andcommitted
Update ValueError message in corr (#25729)
1 parent a5d251d commit 64f5961

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Bug Fixes
124124
~~~~~~~~~
125125
- Bug in :func:`to_datetime` which would raise an (incorrect) ``ValueError`` when called with a date far into the future and the ``format`` argument specified instead of raising ``OutOfBoundsDatetime`` (:issue:`23830`)
126126
- Bug in an error message in :meth:`DataFrame.plot`. Improved the error message if non-numerics are passed to :meth:`DataFrame.plot` (:issue:`25481`)
127-
-
127+
- Bug in error messages in :meth:`DataFrame.corr` and :meth:`Series.corr`. Added the possibility of using a callable. (:issue:`25729`)
128128

129129
Categorical
130130
^^^^^^^^^^^

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7088,8 +7088,8 @@ def corr(self, method='pearson', min_periods=1):
70887088
correl[j, i] = c
70897089
else:
70907090
raise ValueError("method must be either 'pearson', "
7091-
"'spearman', or 'kendall', '{method}' "
7092-
"was supplied".format(method=method))
7091+
"'spearman', 'kendall', or a callable, "
7092+
"'{method}' was supplied".format(method=method))
70937093

70947094
return self._constructor(correl, index=idx, columns=cols)
70957095

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2159,8 +2159,8 @@ def corr(self, other, method='pearson', min_periods=None):
21592159
min_periods=min_periods)
21602160

21612161
raise ValueError("method must be either 'pearson', "
2162-
"'spearman', or 'kendall', '{method}' "
2163-
"was supplied".format(method=method))
2162+
"'spearman', 'kendall', or a callable, "
2163+
"'{method}' was supplied".format(method=method))
21642164

21652165
def cov(self, other, min_periods=None):
21662166
"""

pandas/tests/frame/test_analytics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ def test_corr_cov_independent_index_column(self):
332332
def test_corr_invalid_method(self):
333333
# GH 22298
334334
df = pd.DataFrame(np.random.normal(size=(10, 2)))
335-
msg = ("method must be either 'pearson', 'spearman', "
336-
"or 'kendall'")
335+
msg = ("method must be either 'pearson', "
336+
"'spearman', 'kendall', or a callable, ")
337337
with pytest.raises(ValueError, match=msg):
338338
df.corr(method="____")
339339

pandas/tests/series/test_analytics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ def test_corr_invalid_method(self):
387387
# GH PR #22298
388388
s1 = pd.Series(np.random.randn(10))
389389
s2 = pd.Series(np.random.randn(10))
390-
msg = ("method must be either 'pearson', 'spearman', "
391-
"or 'kendall'")
390+
msg = ("method must be either 'pearson', "
391+
"'spearman', 'kendall', or a callable, ")
392392
with pytest.raises(ValueError, match=msg):
393393
s1.corr(s2, method="____")
394394

0 commit comments

Comments
 (0)