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 618985094,MDU6SXNzdWU2MTg5ODUwOTQ=,4065,keep_attrs not respected for unary operators,500246,closed,0,,,2,2020-05-15T13:55:14Z,2020-10-14T16:29:51Z,2020-10-14T16:29:51Z,CONTRIBUTOR,,,,"The xarray global option `keep_attrs` (introduced in #2482 ) is not respected for unary operators. #### MCVE Code Sample ```python import xarray as xr x = xr.DataArray([1, 2, 3], attrs={""A"": ""B""}) with xr.set_options(keep_attrs=True): y = ~x print(x.attrs, y.attrs) ``` #### Expected Output I expect ``` {'A': 'B'} {'A': 'B'} ``` #### Problem Description I get: ``` {'A': 'B'} {} ``` I get the same for the other unary operators `+x`, `-x`, and `abs(x)`. #### Versions Tested with latest xarray master (see below for details).
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.8.2 | packaged by conda-forge | (default, Mar 23 2020, 18:16:37) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 4.12.14-lp150.12.82-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.4 xarray: 0.15.2.dev64+g2542a63f pandas: 1.0.3 numpy: 1.18.1 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: 2.4.0 cftime: 1.1.1.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.3 cfgrib: None iris: None bottleneck: None dask: 2.14.0 distributed: 2.14.0 matplotlib: 3.2.1 cartopy: 0.17.0 seaborn: None numbagg: None pint: None setuptools: 46.1.3.post20200325 pip: 20.0.2 conda: installed pytest: 5.4.1 IPython: 7.13.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4065/reactions"", ""total_count"": 2, ""+1"": 2, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue