home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 743486313

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/4660#issuecomment-743486313 https://api.github.com/repos/pydata/xarray/issues/4660 743486313 MDEyOklzc3VlQ29tbWVudDc0MzQ4NjMxMw== 14808389 2020-12-11T23:52:36Z 2020-12-11T23:52:36Z MEMBER

inheriting from a Dataset or DataArray is not something we support right now, although that might change in the future.

The reason your examples fail with a RecursionError is a different one, though, you also get the same error if you remove all references to xarray and pass a string to your class. As pointed out in the SO question you referenced, you need to change your __init__: ```python class MyClass: slots = ("dataset",)

def __init__(self, ds):
    self.__class__.dataset.__set__(self, ds)

def __getattr__(self, k):
    return getattr(self.dataset, k)

def __setattr__(self, k, v):
    setattr(self.dataset, k, v)

ds = xr.Dataset() x = MyClass(ds) `` but I've also seen the use ofnewinstead ofinit` to avoid this somewhat ugly trick.

Be aware that the result of __getattr__ as it is right now will remove the custom class, so if you would like to avoid that you will have to add some sort of check: python def __getattr__(self, k): result = getattr(self.dataset, k) if isinstance(result, (xr.Dataset, xr.DataArray)): return type(self)(result) else: return result

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  759270347
Powered by Datasette · Queries took 78.496ms · About: xarray-datasette