home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 443134415

This data as json

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-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) <xarray.DataArray 'temp' (x: 3, y: 3)> 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)

<xarray.DataArray 'temp' (x: 3, y: 3)> 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
Powered by Datasette · Queries took 76.103ms · About: xarray-datasette