From c66db094ea743e1b9e0b8ff3aabf1136986befa3 Mon Sep 17 00:00:00 2001 From: Fabian Rost Date: Thu, 14 Mar 2019 14:21:30 +0100 Subject: [PATCH 1/4] Update ValueError message in corr to include the option of supplying a callable. --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3996728a1cc90..7317682d95256 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7088,8 +7088,8 @@ def corr(self, method='pearson', min_periods=1): correl[j, i] = c else: raise ValueError("method must be either 'pearson', " - "'spearman', or 'kendall', '{method}' " - "was supplied".format(method=method)) + "'spearman', 'kendall', or a callable, " + "'{method}' was supplied".format(method=method)) return self._constructor(correl, index=idx, columns=cols) From 7cb97aa7458be93821d69092516c1d48190efe80 Mon Sep 17 00:00:00 2001 From: Fabian Rost Date: Thu, 14 Mar 2019 15:24:50 +0100 Subject: [PATCH 2/4] update tests --- pandas/tests/frame/test_analytics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 2969e8be2db03..88c8d89ec4b63 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -332,8 +332,8 @@ def test_corr_cov_independent_index_column(self): def test_corr_invalid_method(self): # GH 22298 df = pd.DataFrame(np.random.normal(size=(10, 2))) - msg = ("method must be either 'pearson', 'spearman', " - "or 'kendall'") + msg = ("method must be either 'pearson', " + "'spearman', 'kendall', or a callable, ") with pytest.raises(ValueError, match=msg): df.corr(method="____") From 5a5f73cf9572eca65dd6fff4ab7eae8b86050ccb Mon Sep 17 00:00:00 2001 From: Fabian Rost Date: Thu, 14 Mar 2019 15:25:21 +0100 Subject: [PATCH 3/4] also update for Series --- pandas/core/series.py | 4 ++-- pandas/tests/series/test_analytics.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 03fc26efa4516..04fe3b4407149 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2159,8 +2159,8 @@ def corr(self, other, method='pearson', min_periods=None): min_periods=min_periods) raise ValueError("method must be either 'pearson', " - "'spearman', or 'kendall', '{method}' " - "was supplied".format(method=method)) + "'spearman', 'kendall', or a callable, " + "'{method}' was supplied".format(method=method)) def cov(self, other, min_periods=None): """ diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d7d9c526503cb..13195a0d81d9c 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -387,8 +387,8 @@ def test_corr_invalid_method(self): # GH PR #22298 s1 = pd.Series(np.random.randn(10)) s2 = pd.Series(np.random.randn(10)) - msg = ("method must be either 'pearson', 'spearman', " - "or 'kendall'") + msg = ("method must be either 'pearson', " + "'spearman', 'kendall', or a callable, ") with pytest.raises(ValueError, match=msg): s1.corr(s2, method="____") From d354be99aa30c48c3ccc5d7fd63cef7b4d1e14f6 Mon Sep 17 00:00:00 2001 From: Fabian Rost Date: Thu, 14 Mar 2019 15:25:42 +0100 Subject: [PATCH 4/4] update whatsnew --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 72c40b04a1195..d186fdfe0f322 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -124,7 +124,7 @@ Bug Fixes ~~~~~~~~~ - 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`) - Bug in an error message in :meth:`DataFrame.plot`. Improved the error message if non-numerics are passed to :meth:`DataFrame.plot` (:issue:`25481`) -- +- Bug in error messages in :meth:`DataFrame.corr` and :meth:`Series.corr`. Added the possibility of using a callable. (:issue:`25729`) Categorical ^^^^^^^^^^^