Skip to content

Add the possibility of callable to ValueError message raised by corr #25727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fbnrst opened this issue Mar 14, 2019 · 1 comment · Fixed by #25729
Closed

Add the possibility of callable to ValueError message raised by corr #25727

fbnrst opened this issue Mar 14, 2019 · 1 comment · Fixed by #25729
Labels
Error Reporting Incorrect or improved errors from pandas good first issue
Milestone

Comments

@fbnrst
Copy link
Contributor

fbnrst commented Mar 14, 2019

Code Sample, a copy-pastable example if possible

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

ValueError: method must be either 'pearson', 'spearman', 'kendall' or callable, 'a' was supplied

Output of pd.show_versions()

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
@TomAugspurger TomAugspurger added the Error Reporting Incorrect or improved errors from pandas label Mar 14, 2019
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Mar 14, 2019
@TomAugspurger
Copy link
Contributor

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

@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants