issues: 168876028
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
168876028 | MDU6SXNzdWUxNjg4NzYwMjg= | 933 | rc 0.8: register_dataset_accessor silently ignores AttributeError | 10050469 | closed | 0 | 3 | 2016-08-02T12:44:46Z | 2016-08-03T06:51:22Z | 2016-08-03T06:51:22Z | MEMBER | If an AttributeError is raised at construction time by the accessor, it will be ignored silently: ``` python import xarray as xr @xr.register_dataset_accessor('stupid_accessor')
class GeoAccessor(object):
def init(self, xarray_obj):
self._obj = xarray_obj
ds = xr.Dataset({'longitude': np.linspace(0, 10), 'latitude': np.linspace(0, 20)}) ds.stupid_accessor.plot() ``` Will raise: ``` AttributeError Traceback (most recent call last) <ipython-input-1-b47ffc33cff2> in <module>() 12 13 ds = xr.Dataset({'longitude': np.linspace(0, 10), 'latitude': np.linspace(0, 20)}) ---> 14 ds.stupid_accessor.plot() /home/mowglie/.pyvirtualenvs/py3/lib/python3.4/site-packages/xarray/core/common.py in getattr(self, name) 192 return source[name] 193 raise AttributeError("%r object has no attribute %r" % --> 194 (type(self).name, name)) 195 196 def setattr(self, name, value): AttributeError: 'Dataset' object has no attribute 'stupid_accessor' ``` The problem with this error message is that it doesn't tell you that the problem is in your code. Interestingly, raising other exceptions like ``` RuntimeError Traceback (most recent call last) <ipython-input-1-b575d0257332> in <module>() 12 13 ds = xr.Dataset({'longitude': np.linspace(0, 10), 'latitude': np.linspace(0, 20)}) ---> 14 ds.stupid_accessor.plot() /home/mowglie/.pyvirtualenvs/py3/lib/python3.4/site-packages/xarray/core/extensions.py in get(self, obj, cls) 17 # we're accessing the attribute of the class, i.e., Dataset.geo 18 return self._accessor ---> 19 accessor_obj = self._accessor(obj) 20 # Replace the property with the accessor object. Inspired by: 21 # http://www.pydanny.com/cached-property.html <ipython-input-1-b575d0257332> in init(self, xarray_obj) 5 def init(self, xarray_obj): 6 self._obj = xarray_obj ----> 7 raise RuntimeError('Ups') 8 9 def plot(self): RuntimeError: Ups ``` |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/933/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |