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/2517#issuecomment-434861750,https://api.github.com/repos/pydata/xarray/issues/2517,434861750,MDEyOklzc3VlQ29tbWVudDQzNDg2MTc1MA==,35968931,2018-10-31T21:56:11Z,2018-10-31T21:56:11Z,MEMBER,"That's true, but unless you start subclassing dataset then isn't that always going to be the case?
You have some quantity which you can only calculate with either a function or an accessor method on the dataset, wouldn't you need to alter the `__getitem__` method on the dataset object (or some subclass of it) in order to get the behaviour you're describing?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,374460958
https://github.com/pydata/xarray/issues/2517#issuecomment-434646452,https://api.github.com/repos/pydata/xarray/issues/2517,434646452,MDEyOklzc3VlQ29tbWVudDQzNDY0NjQ1Mg==,35968931,2018-10-31T11:05:18Z,2018-10-31T11:05:18Z,MEMBER,"If you want to return your newly-calculated altitude and also have it be a full data_var in your dataset, one way would be to just alter the original dataset in-place. Something like
```python
import xarray as xr
import pandas as pd
import xarray.testing as xrt
@xr.register_dataset_accessor('acc')
class Accessor(object):
def __init__(self, xarray_ds):
self._ds = xarray_ds
self._altitude = None
@property
def altitude(self):
"""""" An expensive calculation that results in data that not everyone needs. """"""
if self._altitude is None:
self._altitude = xr.DataArray([5, 10, 15, 20, 25],
coords=[('time', self._ds.time)])
# Here we add the calculated altitude to the dataset as a new data variable
self._ds['altitude'] = self._altitude
# Return just the altitude dataarray
return self._altitude
expected = xr.Dataset({'data': (['time'], [100, 30, 10, 3, 1]),
'altitude': (['time'], [5, 10, 15, 20, 25])},
coords={'time': pd.date_range('2014-09-06', periods=5, freq='1s')})
actual = xr.Dataset({'data': (['time'], [100, 30, 10, 3, 1])},
coords={'time': pd.date_range('2014-09-06', periods=5, freq='1s')})
# Return newly-calculated altitude, but also store it in the actual dataset for later
altitude = actual.acc.altitude
# Check that worked
xrt.assert_equal(actual, expected)
xrt.assert_equal(actual['altitude'], actual.acc.altitude)
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,374460958