Skip to content

OptionError raised by top-level function pandas.set_option is private #27553

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
huandzh opened this issue Jul 24, 2019 · 6 comments · Fixed by #32142
Closed

OptionError raised by top-level function pandas.set_option is private #27553

huandzh opened this issue Jul 24, 2019 · 6 comments · Fixed by #32142
Labels
API Design Error Reporting Incorrect or improved errors from pandas good first issue
Milestone

Comments

@huandzh
Copy link

huandzh commented Jul 24, 2019

Code Sample

import pandas as pd
from pandas.errors import OptionError 
# or from pandas import OptionError
option = ('noexist', 1)
try:
    pd.set_option(*option)
except OptionError as e:
    print('Ignore invaild option: {}'.format(option))

Problem description

OptionError is raised by top-level function pandas.set_option, but can only be imported from private module pandas._config.config.

Sample code will failed when importing it from pandas.errors :

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-62b92256ce5f> in <module>
      1 import pandas as pd
----> 2 from pandas.errors import OptionError # or from pandas import OptionError
      3 option = ('noexist', 1)
      4 try:
      5     pd.set_option(*option)

ImportError: cannot import name 'OptionError' from 'pandas.errors' (/home/abc/.local/share/virtualenvs/abc-jIQt2SYy/lib/python3.7/site-packages/pandas/errors/__init__.py)

Expected Output

Ignored invaild option: ('noexist', 1)

Expected behavior : OptionError can be imported from pandas.errors or pandas. And other custom exceptions raised by top-level functions are also available in the same public namespace.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-17763-Microsoft
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.0
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : 0.29.12
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.6.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

@huandzh
Copy link
Author

huandzh commented Jul 24, 2019

see also #19790 #27522

@simonjayhawkins simonjayhawkins added API Design Error Reporting Incorrect or improved errors from pandas labels Jul 24, 2019
@simonjayhawkins
Copy link
Member

@huandzh Thanks for the report.

@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Jul 24, 2019
@huandzh
Copy link
Author

huandzh commented Jul 25, 2019

@simonjayhawkins Glad to help.

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Jul 30, 2019

cc @jbrockmendel I think you recently put effort in separating the _config module from the rest of pandas I think? So putting the error in pandas.errors and importing that in pd._config.config would break that pattern?

(we could also easily, for such case, import the error from pandas._config.config into pandas.errors, although in general it is better the other way around to see the correct code path of the error)

@jorisvandenbossche
Copy link
Member

See also #27656, I made a general issue for all custom errors/warnings.

@jbrockmendel
Copy link
Member

The idea for _config is to treat it as entirely upstream of the rest of pandas, so yah, importing it into pandas.errors is teh way to go.

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

Successfully merging a pull request may close this issue.

5 participants