Skip to content
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

Merged
merged 9 commits into from
Feb 24, 2018

Conversation

jayfoad
Copy link
Contributor

@jayfoad jayfoad commented Feb 20, 2018

@pep8speaks
Copy link

pep8speaks commented Feb 20, 2018

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
Copy link

codecov bot commented Feb 20, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@e8b80b1). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #19790   +/-   ##
=========================================
  Coverage          ?   91.58%           
=========================================
  Files             ?      150           
  Lines             ?    48911           
  Branches          ?        0           
=========================================
  Hits              ?    44796           
  Misses            ?     4115           
  Partials          ?        0
Flag Coverage Δ
#multiple 89.96% <100%> (?)
#single 41.77% <0%> (?)
Impacted Files Coverage Δ
pandas/core/config.py 87.17% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e8b80b1...ac53036. Read the comment docs.

Copy link
Contributor

@jreback jreback left a 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

@@ -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

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Compat pandas objects compatability with Numpy or Python functions labels Feb 21, 2018
@@ -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`)
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

@jayfoad jayfoad Feb 23, 2018

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
Copy link
Contributor

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

@jreback jreback added this to the 0.23.0 milestone Feb 24, 2018
@jreback jreback merged commit ecef6d0 into pandas-dev:master Feb 24, 2018
@jreback
Copy link
Contributor

jreback commented Feb 24, 2018

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas.options.__getattr__ raises KeyError instead of AttributeError
4 participants