Skip to content

Raise OptionError instead of KeyError in __getattr__. Fixes #19789. #19790

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

Merged
merged 9 commits into from
Feb 24, 2018
5 changes: 4 additions & 1 deletion pandas/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ def __getattr__(self, key):
if prefix:
prefix += "."
prefix += key
v = object.__getattribute__(self, "d")[key]
d = object.__getattribute__(self, "d")
if key not in d:
Copy link
Contributor

Choose a reason for hiding this comment

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

slightly more idiomatic to use a try/except here (to catch the KeyError) and raise the OptionError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

raise OptionError("No such option")
v = d[key]
if isinstance(v, dict):
return DictWrapper(v, prefix)
else:
Expand Down