-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Raise OptionError instead of KeyError in __getattr__. Fixes #19789. #19790
Conversation
Hello @jayfoad! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on February 24, 2018 at 15:07 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #19790 +/- ##
=========================================
Coverage ? 91.58%
=========================================
Files ? 150
Lines ? 48911
Branches ? 0
=========================================
Hits ? 44796
Misses ? 4115
Partials ? 0
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a test & can you add a whatsnew in bug fixes / other
pandas/core/config.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -876,3 +876,4 @@ Other | |||
^^^^^ | |||
|
|||
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`) | |||
- Bug in :func:`pandas.core.DictWrapper.__getattr__` when looking up a non-existent key (:issue:`19789`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe the bug a bit? Mention it raising a KeyError
instead of the correct OptionError
.
@@ -428,3 +428,7 @@ def test_option_context_scope(self): | |||
|
|||
# Ensure the current context is reset | |||
assert self.cf.get_option(option_name) == original_value | |||
|
|||
def test_dictwrapper_getattr(self): | |||
options = self.cf.options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use an with pytest.raises here to check for the OptionError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As well as the hasattr test or instead of it? hasattr already tests for AttributeError.
@@ -428,3 +428,7 @@ def test_option_context_scope(self): | |||
|
|||
# Ensure the current context is reset | |||
assert self.cf.get_option(option_name) == original_value | |||
|
|||
def test_dictwrapper_getattr(self): | |||
options = self.cf.options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue number as a comment here
thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff