issues: 1233594189
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1233594189 | I_kwDOAMm_X85JhydN | 6596 | xr.where() failed when xr.set_options(keep_attrs=True) | 72398463 | closed | 0 | 1 | 2022-05-12T07:58:02Z | 2022-05-12T08:02:56Z | 2022-05-12T08:02:56Z | NONE | What happened?xr.where() used to change the values between 0 or 1 in a dataset/dataArray given a condition. xr.set_options(keep_attrs=True) to keep attributes on xarray Datasets/dataarrays after operations. xr. where() failed What did you expect to happen?No response Minimal Complete Verifiable Example```Python import numpy as np import xarray as xr x = xr.DataArray(
) x <xarray.DataArray 'sst' (lat: 10)> array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]) Coordinates: * lat (lat) int64 0 1 2 3 4 5 6 7 8 9 xr.where((x < 0.5), 0, 1) <xarray.DataArray 'sst' (lat: 10)> array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) Coordinates: * lat (lat) int64 0 1 2 3 4 5 6 7 8 9 xr.set_options(keep_attrs=True) <xarray.core.options.set_options object at 0x7f7c5bb12f10> xr.where((x < 0.5), 0, 1) Traceback (most recent call last): File "/home/cuadradot/miniconda3/envs/metro_validation/lib/python3.9/code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in <module> File "/home/cuadradot/miniconda3/envs/metro_validation/lib/python3.9/site-packages/xarray/core/computation.py", line 1815, in where return apply_ufunc( File "/home/cuadradot/miniconda3/envs/metro_validation/lib/python3.9/site-packages/xarray/core/computation.py", line 1159, in apply_ufunc return apply_dataarray_vfunc( File "/home/cuadradot/miniconda3/envs/metro_validation/lib/python3.9/site-packages/xarray/core/computation.py", line 286, in apply_dataarray_vfunc result_var = func(*data_vars) File "/home/cuadradot/miniconda3/envs/metro_validation/lib/python3.9/site-packages/xarray/core/computation.py", line 743, in apply_variable_ufunc attrs = merge_attrs( File "/home/cuadradot/miniconda3/envs/metro_validation/lib/python3.9/site-packages/xarray/core/merge.py", line 518, in merge_attrs return combine_attrs(variable_attrs, context=context) File "/home/cuadradot/miniconda3/envs/metro_validation/lib/python3.9/site-packages/xarray/core/computation.py", line 1812, in <lambda> keep_attrs = lambda attrs, context: attrs[1] IndexError: list index out of range ``` MVCE confirmation
Relevant log outputNo response Anything else we need to know?No response Environment
commit: None
python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:22:55)
[GCC 10.3.0]
python-bits: 64
OS: Linux
OS-release: 5.13.0-27-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.1
libnetcdf: 4.8.1
xarray: 2022.3.0
pandas: 1.4.2
numpy: 1.22.3
scipy: 1.8.0
netCDF4: 1.5.8
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.4
dask: 2022.04.1
distributed: 2022.4.1
matplotlib: 3.5.1
cartopy: 0.20.2
seaborn: 0.11.2
numbagg: None
fsspec: 2022.3.0
cupy: None
pint: None
sparse: 0.13.0
setuptools: 62.1.0
pip: 22.0.4
conda: None
pytest: None
IPython: None
sphinx: None
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/6596/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |