Skip to content
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

Encoding not preserved when using where function #2291

Closed
jlandmann opened this issue Jul 16, 2018 · 3 comments
Closed

Encoding not preserved when using where function #2291

jlandmann opened this issue Jul 16, 2018 · 3 comments

Comments

@jlandmann
Copy link

My first issue in xarray, so I'd first of all thank you so much for this great package!

Code Sample, a copy-pastable example if possible

da = xr.DataArray(np.random.randn(2, 3), encoding={'_FillValue': np.nan})
da.encoding 
# {'_FillValue': nan}
da_where = da.where(1)
da_where.encoding
# {}

Problem description

This is a problem I stumbled upon when using the roi method of salem (see here), but @fmaussion brought up the very good idea to maybe fix this upstream: when using the .where method, the encoding of the dataset/the dataarray is not preserved. Could this be changed or is there any specific reason (conflict?) why this is dropped?

Expected Output

da_where.encoding
# {'_FillValue': nan}

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None xarray: 0.10.4 pandas: 0.22.0 numpy: 1.11.3 scipy: 1.0.1 netCDF4: 1.2.7 h5netcdf: 0.3.1 h5py: 2.6.0 Nio: None zarr: None bottleneck: 1.2.0 cyordereddict: 1.0.0 dask: 0.15.1 distributed: 1.17.0 matplotlib: 2.2.0 cartopy: None seaborn: None setuptools: 40.0.0 pip: 10.0.1 conda: 4.5.8 pytest: 2.9.2 IPython: 5.1.0 sphinx: 1.7.5
@shoyer
Copy link
Member

shoyer commented Jul 16, 2018

Thanks for raising this. Please take a look at #1614. I'd love to figure out a more comprehensive set of rules for what xarray should do for propagating encoding/attributes in every operation. Proposals and opinions would be very welcome!

@jlandmann
Copy link
Author

Thanks for your comment @shoyer and sorry for not having found the issue you refer to!
So in favor of a low number of open issues, what would you suggest? Should I just add the where case to #1614 and we close this?

@dcherian
Copy link
Contributor

I've added where to the table in #1614 with keep as default for both encoding and attrs.

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

3 participants