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/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-443786550,https://api.github.com/repos/pydata/xarray/issues/2582,443786550,MDEyOklzc3VlQ29tbWVudDQ0Mzc4NjU1MA==,2448579,2018-12-03T17:04:24Z,2018-12-03T17:04:24Z,MEMBER,"Hi @MBlaschek, almost there! You'll need to open your pull request in this repository :). You'll also need to add some tests to make sure your changes keep working as the code is updated in the future. E.g. https://github.com/pydata/xarray/blob/0d6056e8816e3d367a64f36c7f1a5c4e1ce4ed4e/xarray/tests/test_variable.py#L1533","{""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-443286361,https://api.github.com/repos/pydata/xarray/issues/2582,443286361,MDEyOklzc3VlQ29tbWVudDQ0MzI4NjM2MQ==,2448579,2018-11-30T17:57:47Z,2018-11-30T17:57:47Z,MEMBER,"@MBlaschek This might help: https://help.github.com/articles/proposing-changes-to-your-work-with-pull-requests/ . You'd start by creating a fork, then a branch with your changes, push your changes to github and then initiate a pull request.","{""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-443285132,https://api.github.com/repos/pydata/xarray/issues/2582,443285132,MDEyOklzc3VlQ29tbWVudDQ0MzI4NTEzMg==,5635139,2018-11-30T17:53:48Z,2018-11-30T17:53:48Z,MEMBER,"> Not sure what a PR is. (Sorry I'm not that advanced in coding) PR is a pull-request! If you can open a PR with your code, we can merge it to the repo. Would be greatly appreciated from xarray, and you'd be an xarray contributor. Let us know if we can help guide you through the mechanics.","{""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 https://github.com/pydata/xarray/issues/2582#issuecomment-442975920,https://api.github.com/repos/pydata/xarray/issues/2582,442975920,MDEyOklzc3VlQ29tbWVudDQ0Mjk3NTkyMA==,1217238,2018-11-29T20:09:29Z,2018-11-29T20:09:29Z,MEMBER,"Thanks for the report! It looks like we definitely overlooked this in arithmetic operations. I agree that `keep_attrs=True` should mean that attributes are maintained in arithmetic. Any interest in putting together a PR? - https://github.com/pydata/xarray/pull/2482 has lots of examples of how to implement the option. - https://github.com/pydata/xarray/blob/0d6056e8816e3d367a64f36c7f1a5c4e1ce4ed4e/xarray/core/variable.py#L1665 is where we forget to keep attributes in binary operations.","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,385716625