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/pull/2590#issuecomment-446866434,https://api.github.com/repos/pydata/xarray/issues/2590,446866434,MDEyOklzc3VlQ29tbWVudDQ0Njg2NjQzNA==,8898319,2018-12-13T07:16:23Z,2018-12-13T07:16:23Z,CONTRIBUTOR,Cool. I will keep using Xarray. Thanks for the great work,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,387673324 https://github.com/pydata/xarray/pull/2590#issuecomment-446546926,https://api.github.com/repos/pydata/xarray/issues/2590,446546926,MDEyOklzc3VlQ29tbWVudDQ0NjU0NjkyNg==,8898319,2018-12-12T10:57:46Z,2018-12-12T10:57:46Z,CONTRIBUTOR,"I hope that is all you guys wanted. It's kinda complicated for me to follow all these procedures to do really simple thing. I hope that helps and thanks for the inside into pull-requests. Please let me know if I can close it and be done with it.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,387673324 https://github.com/pydata/xarray/issues/2582#issuecomment-444423133,https://api.github.com/repos/pydata/xarray/issues/2582,444423133,MDEyOklzc3VlQ29tbWVudDQ0NDQyMzEzMw==,8898319,2018-12-05T09:45:03Z,2018-12-05T09:45:03Z,CONTRIBUTOR,"Hi. Ok Sorry. Had no idea what I was doing. So I hope I fixed it, the way you wanted. I added a test-routine `test_binary_ops_keep_attrs` Created a new pull request, as I could not reopen the old one","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,385716625 https://github.com/pydata/xarray/issues/2582#issuecomment-443134415,https://api.github.com/repos/pydata/xarray/issues/2582,443134415,MDEyOklzc3VlQ29tbWVudDQ0MzEzNDQxNQ==,8898319,2018-11-30T08:51:19Z,2018-11-30T08:51:19Z,CONTRIBUTOR,"Thanks for the quick reply. Not sure what a PR is. (Sorry I'm not that advanced in coding) I figure, from code you have been using at other places, something like that ```python @staticmethod def _binary_op(f, reflexive=False, **ignored_kwargs): @functools.wraps(f) def func(self, other): if isinstance(other, (xr.DataArray, xr.Dataset)): return NotImplemented self_data, other_data, dims = _broadcast_compat_data(self, other) # Add Attributes here ? keep_attrs = _get_keep_attrs(default=False) attrs = self._attrs if keep_attrs else None with np.errstate(all='ignore'): new_data = (f(self_data, other_data) if not reflexive else f(other_data, self_data)) result = Variable(dims, new_data, attrs=attrs) return result return func ``` should do the trick. Right. I cloned the recent version and tried out the new code. It works! :)
xr.show_versions() INSTALLED VERSIONS ------------------ commit: 0d6056e8816e3d367a64f36c7f1a5c4e1ce4ed4e python: 3.6.6 |Anaconda, Inc.| (default, Oct 9 2018, 12:34:16) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 4.15.0-39-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.2 libnetcdf: 4.6.1 xarray: 0.11.0+10.g0d6056e8.dirty pandas: 0.23.4 numpy: 1.15.4 scipy: 1.1.0 netCDF4: 1.4.2 pydap: None h5netcdf: None h5py: 2.8.0 Nio: None zarr: None cftime: 1.0.2.1 PseudonetCDF: None rasterio: None cfgrib: installed iris: None bottleneck: 1.2.1 cyordereddict: None dask: 0.20.2 distributed: 1.24.2 matplotlib: 3.0.1 cartopy: 0.16.0 seaborn: 0.9.0 setuptools: 40.6.2 pip: 18.1 conda: 4.5.11 pytest: 4.0.0 IPython: 7.1.1 sphinx: 1.8.2
When the option is not set, same behavior as before ```python print(a-b) array([[ 0.133102, -1.275794, 1.331784], [ 0.995555, -0.509624, 0.188597], [ 1.922048, -0.053253, -0.293245]]) Dimensions without coordinates: x, y ``` set the option: ```python with xr.set_options(keep_attrs=True): print(a-b) array([[ 0.133102, -1.275794, 1.331784], [ 0.995555, -0.509624, 0.188597], [ 1.922048, -0.053253, -0.293245]]) Dimensions without coordinates: x, y Attributes: units: K ``` works. Hope that helps you. ","{""total_count"": 3, ""+1"": 3, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,385716625