issue_comments: 559847335
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/3582#issuecomment-559847335 | https://api.github.com/repos/pydata/xarray/issues/3582 | 559847335 | MDEyOklzc3VlQ29tbWVudDU1OTg0NzMzNQ== | 6213168 | 2019-11-29T17:10:40Z | 2019-11-29T17:10:40Z | MEMBER | +1 to shoyer - encapsulation is by far the easiest approach.
```python @xarray.register_dataset_accessor('foo') class FooAccessor: def init(self, xarray_obj): self.obj = xarray_obj # <insert whatever health checks on xarray_obj> self.x = something(xarray_obj)
``` The accessor Note, however, that it is not recommended to put expensive calculations in it, because the object will possibly be destroyed and reinitialised every time the array is transformed - or in other words, anything that is not a read-only method/property or a cell update. I emphasized possibly because some transforms may not destroy and recreate your accessor instance, thus potentially causing it to be in a state that is incoherent with the attached xarray object. Every time you invoke a method, you should verify that whatever assumptions you relied upon to generate the state are still valid. |
{ "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
530062582 |