Skip to content

Inconsistent name behavior in masking #2748

@yohai

Description

@yohai

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions