-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Masking and preserving int type #3955
Comments
There has been a lot of discussion about the int vs nan problem in the past, here one issue #1194. My question for xarray-devs would be too, if there is some idea on adapting to the pandas scheme? In the time being, you might just go the other way round ( # overwrite fill_values with 0
sub = xr.where(z_indices == fill_value, 0, z_indices)
# isel with sub and mask with where
indexed_array = val_arr.isel(z=sub).where(z_indices != fill_value) Update: Nevermind, this will make the # overwrite fill_values with 0
sub = xr.where(z_indices == fill_value, 0, z_indices)
# isel with sub and mask with where
indexed_array = val_arr.isel(z=sub)
indexed_array = xr.where(z_indices == fill_value, fill_value, indexed_array) I can't immediately see, but there might be a cleaner way to achieve this. |
@kmuehlbauer Thanks, Nice trick! It works well for this situation. |
I would love to have support for integer NA values in xarray, but I don't think we want to build it into xarray. Ideally this would either be built into NumPy (i.e., with a custom dtype, which will require some work before its possible) or someone could build an "integer with NA" duckarray, which could implement the various NumPy protocols such as |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
Closing as an upstream issue. We need either numpy to add support or for pandas extensionarrays to support the necssary protocols (#5287) |
When DataArray is masked by
.where()
, the type is converted tofloat64
.But, if we need to use the DataArray ouput from
.where()
in.isel()
, the dtype should beint
.(#3949 )
MCVE Code Sample
Expected Output
Problem Description
Currently, pandas supports NaN values. Is this possible for xarray? or another method around?
The text was updated successfully, but these errors were encountered: