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-758347487,https://api.github.com/repos/pydata/xarray/issues/4660,758347487,MDEyOklzc3VlQ29tbWVudDc1ODM0NzQ4Nw==,5635139,2021-01-12T02:13:15Z,2021-01-12T02:13:15Z,MEMBER,"Though we don't support it officially, I've found subclassing a `Dataset` can be useful when adding methods. Most operations on the object will not persist the subclass, though.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,759270347 https://github.com/pydata/xarray/issues/4660#issuecomment-758312392,https://api.github.com/repos/pydata/xarray/issues/4660,758312392,MDEyOklzc3VlQ29tbWVudDc1ODMxMjM5Mg==,14808389,2021-01-12T00:31:01Z,2021-01-12T00:31:01Z,MEMBER,"I assume this answered your question. If you disagree, feel free to reopen.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,759270347 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](https://xarray.pydata.org/en/stable/internals.html#extending-xarray), although that might [change](https://github.com/pydata/xarray/issues/3980) 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 of `__new__` instead of `__init__` 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