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/5436#issuecomment-872210975,https://api.github.com/repos/pydata/xarray/issues/5436,872210975,MDEyOklzc3VlQ29tbWVudDg3MjIxMDk3NQ==,31376402,2021-07-01T12:37:52Z,2021-07-01T12:37:52Z,CONTRIBUTOR,"@keewis thank you for the reply
> To fix this, I would vote for not using `promote_attrs=True` in `merge` (low confidence vote, though, I'm sure there was a reason for that). We could also try to allow specifying separate strategies for main object and variables, but that looks somewhat complicated (_and_ I'm still not sure what syntax we could use for that).
Does this mean that my workaround is not fully working as I would like it to? (I want it to basically do nothing to the attrs)
Is it possible at the moment to pass `promote_attrs=False` to `xr.merge()`?
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,911513701
https://github.com/pydata/xarray/issues/5436#issuecomment-871681764,https://api.github.com/repos/pydata/xarray/issues/5436,871681764,MDEyOklzc3VlQ29tbWVudDg3MTY4MTc2NA==,31376402,2021-06-30T19:49:24Z,2021-06-30T19:49:24Z,CONTRIBUTOR,"Hey guys! First of all thank you for the work on maintaining this package 😃
I am running into the same issue and it is partially blocking an [open-source package](https://gitlab.com/quantify-os/quantify-core) (used in experimental quantum computing) from adopting the latest version of xarray.
For our typical dataset this happens:
```python
import xarray as xr
import numpy as np
x0 = xr.DataArray(data=np.ones(5), name=""x0"", attrs={
'name': 'x', 'long_name': 'X position', 'units': 'm', 'batched': False})
y0 = xr.DataArray(data=np.ones(5), name=""y0"", attrs={
'name': 'y', 'long_name': 'Y position', 'units': 'm', 'batched': True})
ds = xr.merge([x0, y0])
print(ds)
```
```bash
Dimensions: (dim_0: 5)
Dimensions without coordinates: dim_0
Data variables:
x0 (dim_0) float64 1.0 1.0 1.0 1.0 1.0
y0 (dim_0) float64 1.0 1.0 1.0 1.0 1.0
Attributes:
name: x
long_name: X position
units: m
batched: False
```
As default behavior this is totally unexpected because the variables attributes have nothing to do with the dataset itself. I am just trying to put all my data in a single container. (Am i using the wrong function for this?)
And second, `combine_attrs` has no option for ""do nothing"" which was the behavior in xarray `0.17.0`. I noticed the current master brach allows passing a function but not sure if that solves the problem. The `""drop""` option indeed acts in very weird way, I tried it in the hope that it will drop `attrs` on the resulting dataset instead of affecting the attributes of the variables.
My suggestion is to do nothing by default, i.e. `combine_attrs = None`, simply does not try to combine the attribute in any way.
I understand there might be cases where combining the attributes makes sense, so maybe my suggestion only applies when **only** `DataArray`s objects are merged into a `Dataset` (If i recall correctly the ""what's new"" list, this will be already enforced in `0.18.3`).
Hope my use case helps this discussion.
---
In the meantime the workaround seems to be: `combine_attrs = ""override""` (because it will not (?) affect the attributes of the variables) + and wipe attrs afterwards with `dataset.attrs = dict()`:
```python
import xarray as xr
import numpy as np
x0 = xr.DataArray(data=np.ones(5), name=""x0"", attrs={
'name': 'x', 'long_name': 'X position', 'units': 'm', 'batched': False})
y0 = xr.DataArray(data=np.ones(5), name=""y0"", attrs={
'name': 'y', 'long_name': 'Y position', 'units': 'm', 'batched': True})
ds = xr.merge([x0, y0])
ds.attrs = dict()
print(ds)
print(""==="")
print(ds.x0)
```
```bash
Dimensions: (dim_0: 5)
Dimensions without coordinates: dim_0
Data variables:
x0 (dim_0) float64 1.0 1.0 1.0 1.0 1.0
y0 (dim_0) float64 1.0 1.0 1.0 1.0 1.0
===
array([1., 1., 1., 1., 1.])
Dimensions without coordinates: dim_0
Attributes:
name: x
long_name: X position
units: m
batched: False
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,911513701