OptionError raised by top-level function pandas.set_option is private · Issue #27553 · pandas-dev/pandas (original) (raw)

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