Skip to content

AttributeError raised inside property of DataFrame hides error source. #11808

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
benavente opened this issue Dec 9, 2015 · 2 comments · Fixed by #11822
Closed

AttributeError raised inside property of DataFrame hides error source. #11808

benavente opened this issue Dec 9, 2015 · 2 comments · Fixed by #11822
Labels
Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@benavente
Copy link

When an AttributeError is raised inside a property in DataFrame, regular attribute access fails and __getattr__ in NDFrame is called.
Since the property's attribute name is neither in _internal_names_set nor _info_axis, a new exception is risen and the original stack trace is lost.

import pandas as pd

class A(pd.DataFrame):    
    @property
    def foo(self):
        return 1 / 0

    @property
    def bar(self):
        return self.i_dont_exist

>>> a = A()

>>> a.foo
ZeroDivisionError

>>> a.bar
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-35-0eea75f4bdee> in <module>()
     12 #a.foo  # ZeroDivisionError
     13 
---> 14 a.bar  # AttributeError: 'A' object has no attribute 'bar'
     15 
     16 #a.i_dont_exist  # AttributeError: 'str' object has no attribute 'isnull'

/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in __getattr__(self, name)
   2148                 return self[name]
   2149             raise AttributeError("'%s' object has no attribute '%s'" %
-> 2150                                  (type(self).__name__, name))
   2151 
   2152     def __setattr__(self, name, value):

AttributeError: 'A' object has no attribute 'bar'

>>> a.i_dont_exist  # a.bar should include this in the stack trace:
AttributeError: 'A' object has no attribute 'i_dont_exist'
>>> pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-39-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.16.2
nose: 1.3.7
Cython: 0.23.4
numpy: 1.10.1
scipy: 0.16.0
statsmodels: None
IPython: 4.0.0
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.6
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.3.2
html5lib: 0.999
httplib2: 0.9
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
@jreback
Copy link
Contributor

jreback commented Dec 10, 2015

I am not entirely sure why this happens. The exception (on the inner property) is somehow not propogating up the stack. care to have a look and investigate?

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Difficulty Intermediate labels Dec 10, 2015
@kawochen
Copy link
Contributor

this can be fixed by always falling back on object.__getattribute__ in NDFrame... I will run tests and see if anything fails

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

Successfully merging a pull request may close this issue.

3 participants