Repository: pandas-dev/pandas

Issue:
Add the possibility of callable to ValueError message raised by corr
#### Code Sample, a copy-pastable example if possible

```python
import pandas as pd
from scipy.stats import pearsonr

df = pd.DataFrame({'A': [1,2,3], 'B': [2,5,6]})
df.corr(method='a')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-19-be8a09a85708> in <module>
      2 
      3 df = pd.DataFrame({'A': [1,2,3], 'B': [2,5,6]})
----> 4 df.corr(method='a')

~/miniconda3/envs/spols190117/lib/python3.6/site-packages/pandas/core/frame.py in corr(self, method, min_periods)
   7034             raise ValueError("method must be either 'pearson', "
   7035                              "'spearman', or 'kendall', '{method}' "
-> 7036                              "was supplied".format(method=method))
   7037 
   7038         return self._constructor(correl, index=idx, columns=cols)

ValueError: method must be either 'pearson', 'spearman', or 'kendall', 'a' was supplied
```
#### Problem description

The `ValueError` in the example above does not mention that a `callable` could be supplied to `corr` as well. I would suggest to add this to the error message.

#### Expected Output

```python
ValueError: method must be either 'pearson', 'spearman', 'kendall' or callable, 'a' was supplied
```

#### Output of ``pd.show_versions()``

<details>

```python
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.165-81-default
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: 4.1.1
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.3
numpy: 1.15.4
scipy: 1.2.0
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: 1.8.3
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.2
openpyxl: 2.4.0-b1
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: 4.3.0
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
```
</details>



Discussion:
Slight adjustment to your expected error message, I would phrase it as "a callable", since the function / type `callable` isn't valid.

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- 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)
 
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- 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):
         """


Test patch:
diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py
--- 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="____")
 
diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py
--- 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="____")