issues: 503425825
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
503425825 | MDU6SXNzdWU1MDM0MjU4MjU= | 3376 | .coarsen() method for the xarray.Dataset removes its attributes. | 3642622 | closed | 0 | 4 | 2019-10-07T12:39:14Z | 2020-03-02T23:02:55Z | 2020-03-02T23:02:55Z | NONE | Hello, I am not sure if this is a bug or a feature but when one calls the xarray.coarsen() on a dataset, then the attributes get removed. Dataset Example ```python import xarray as xr import numpy as np var1 = np.linspace(10, 15, 100) var2 = np.linspace(5, 10, 100) coords = np.linspace(1, 10, 100) dat = xr.Dataset( data_vars={'var1': ('coord', var1), 'var2': ('coord', var2)}, coords={'coord': coords} ) dat.attrs['model_id'] = 'model1' coarsen datasetdat = dat.coarsen(coord=5).mean() print datasetdat ``` Actual Output
Expected Output
Problem DescriptionI believe the attributes should stay within the xarray.Dataset no matter what the operations that are done on it. Obviously maybe for some operations an entry like model_id could change because it's no longer the model. But I believe that should be left up to the user. Perhaps a warning in the docs might be sufficient. The behaviour isn't consistent with the xarray.coarsen() function on the xarray.DataArray example where the attributes remain the same (see details below). DataArray Example
```python
data = np.random.rand(50, 3)
locs = ['IA', 'IL', 'IN']
times = pd.date_range('2000-01-01', periods=50)
foo = xr.DataArray(data, coords=[times, locs], dims=['time', 'space'])
foo.attrs['data_id'] = 'data1'
foo
```
#### Expected/Actual Output
```python
<xarray.DataArray (time: 10, space: 3)>
array([[0.3537571 , 0.50698482, 0.35923528],
[0.62127828, 0.41852822, 0.5617278 ],
[0.38669858, 0.60446037, 0.45699182],
[0.41538186, 0.81251298, 0.3919821 ],
[0.67914214, 0.45866817, 0.58625095],
[0.63560785, 0.53796635, 0.48231731],
[0.60802724, 0.54003065, 0.38456255],
[0.46492592, 0.78542293, 0.50788668],
[0.53757801, 0.56765902, 0.52288412],
[0.51085502, 0.51448292, 0.67426125]])
Coordinates:
* time (time) datetime64[ns] 2000-01-03 2000-01-08 ... 2000-02-17
* space (space) <U2 'IA' 'IL' 'IN'
Attributes:
data_id: data1
```
</details>
Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/3376/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |