Skip to content

Fix PandasOptionError import. #99

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
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion odps/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ def __init__(self, *args, **kw):
def getvalue(self, silent=False):
if self._use_pd:
import pandas as pd
from pandas.core.config import OptionError as PandasOptionError
if pd.__version__ < '0.25.0':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try import pandas.core.config, if failed, try to import pandas._config.config. Documents can be added about pandas version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do that now.

But it seems not right to handle compatibility issues with exceptions (exceptions are most likely to be something go unexpected).

OptionError is private in '0.25.0' , but may be published and move to another place afterwards. We can't handle updates directly with ImportError then.

Any idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think try except is a better way. How about just make a modification?

We cannot predict the behavior of pandas in the future, let's fix the current issue first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you given some more reasoning? I really can't understand why try except is preferred in this use case. Importing from pandas.core.config will sure fail in current and future versions.

And code already committed here did fix the issue.

See also:

pandas-dev/pandas#27553
pandas-dev/pandas#27656

from pandas.core.config import OptionError as PandasOptionError
else:
# `pandas.core` was moved to `pandas._config`
# and made private after `v0.25.0`
from pandas._config.config import OptionError as PandasOptionError
try:
return pd.get_option('.'.join(self._items))
except PandasOptionError:
Expand Down