Skip to content

Inconsistent name behavior in masking #2748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yohai opened this issue Feb 6, 2019 · 2 comments
Closed

Inconsistent name behavior in masking #2748

yohai opened this issue Feb 6, 2019 · 2 comments

Comments

@yohai
Copy link
Contributor

yohai commented Feb 6, 2019

Code Sample, a copy-pastable example if possible

Consider the following 4 ways to mask an DataArray:

import xarray as xr

ds=xr.Dataset({'a': (['x'], range(10))},
              coords={'x': range(10)})
ds['msk']=ds.a>5
msk=ds.a>5

v1=ds.a.where(ds.a>5)
v2=ds.a.where(msk)
v3=ds.where(ds.msk).a
v4=ds.a.where(ds.msk)

', '.join(str(v.name) for v in (v1, v2, v3, v4))```
 #output:
'a, a, a, None'

Problem description

All vs defined above are identical, except that v4 has lost its name in masking. This can cause errors in merging (like just happened to me and was hard and annoying to catch).

Is this behavior intentional? It seems inconsistent to me that ds.a.where(ds.msk) is not equivalent to ds.where(ds.msk).a

Expected Output

I would expect ds.a.where(ds.msk) to return a DataArray with the name a.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.2 (default, Dec 29 2018, 00:00:04) [Clang 4.0.1 (tags/RELEASE_401/final)] python-bits: 64 OS: Darwin OS-release: 18.2.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: None libnetcdf: None

xarray: 0.11.1+49.g27cf53f2
pandas: 0.23.3
numpy: 1.16.0
scipy: 1.2.0
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.2.0
cftime: 1.0.3.4
PseudonetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.1
cyordereddict: None
dask: 1.1.0
distributed: 1.25.3
matplotlib: 3.0.2
cartopy: 0.17.0
seaborn: 0.9.0
setuptools: 40.8.0
pip: 19.0.1
conda: None
pytest: None
IPython: 7.2.0
sphinx: 1.8.2

@dcherian
Copy link
Contributor

dcherian commented Feb 7, 2019

Duplicate of #2457? PRs welcome :)

@yohai yohai mentioned this issue Feb 7, 2019
3 tasks
@yohai
Copy link
Contributor Author

yohai commented Feb 7, 2019

@dcherian here: #2749. I think it's very simple, but I might be missing something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants