-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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 v
s 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()
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