You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code above executes without issues in xarray version 0.10.8. However, it results in a "shape-mismatch" error in 0.10.9:
Traceback (most recent call last):
File "<ipython-input-57-f099072e9750>", line 8, in <module>
newda = da.reindex_like(like)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\dataarray.py", line 919, in reindex_like
**indexers)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\dataarray.py", line 969, in reindex
indexers=indexers, method=method, tolerance=tolerance, copy=copy)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\dataset.py", line 1924, in reindex
tolerance, copy=copy)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\alignment.py", line 377, in reindex_variables
new_var = var._getitem_with_mask(key)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\variable.py", line 655, in _getitem_with_mask
data = duck_array_ops.where(mask, fill_value, data)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\duck_array_ops.py", line 183, in where
return _where(condition, *as_shared_dtype([x, y]))
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\duck_array_ops.py", line 115, in as_shared_dtype
arrays = [asarray(x) for x in scalars_or_arrays]
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\duck_array_ops.py", line 115, in <listcomp>
arrays = [asarray(x) for x in scalars_or_arrays]
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\duck_array_ops.py", line 110, in asarray
return data if isinstance(data, dask_array_type) else np.asarray(data)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\numpy\core\numeric.py", line 492, in asarray
return array(a, dtype, copy=False, order=order)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\indexing.py", line 624, in __array__
self._ensure_cached()
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\indexing.py", line 621, in _ensure_cached
self.array = NumpyIndexingAdapter(np.asarray(self.array))
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\numpy\core\numeric.py", line 492, in asarray
return array(a, dtype, copy=False, order=order)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\indexing.py", line 602, in __array__
return np.asarray(self.array, dtype=dtype)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\numpy\core\numeric.py", line 492, in asarray
return array(a, dtype, copy=False, order=order)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\indexing.py", line 508, in __array__
return np.asarray(array[self.key], dtype=None)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\backends\rasterio_.py", line 119, in __getitem__
key, self.shape, indexing.IndexingSupport.OUTER, self._getitem)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\core\indexing.py", line 776, in explicit_indexing_adapter
result = raw_indexing_method(raw_key.tuple)
File "d:\bootsma\miniconda3\envs\main\lib\site-packages\xarray\backends\rasterio_.py", line 115, in _getitem
return out[np_inds]
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (10,) (16,)
I only get it to occur when loading a raster using open_rasterio(). Defining da directly does not lead to issues, using either numpy or dask.array.
So it looks to me like some lazy evaluation is going awry when open_rasterio is involved, in this case.
Anything which forces a compute() before reindex_like in this case seems to make the problem go away, like calling da in the console, print(da) after opening the .tif, etc.
Thanks for the clear code to reproduce. I can verify this on the latest development version of xarray.
Anything which forces a compute() before reindex_like in this case seems to make the problem go away, like calling da in the console, print(da) after opening the .tif, etc.
This is because open_rasterio() defaults to cache=True. If you turn off caching, this bug reproduces itself reliably: da = xr.open_rasterio("basic.tif", cache=False).squeeze("band", drop=True)
Code Sample
Problem description
The code above executes without issues in xarray version 0.10.8. However, it results in a "shape-mismatch" error in 0.10.9:
I only get it to occur when loading a raster using
open_rasterio()
. Definingda
directly does not lead to issues, using either numpy or dask.array.The "shape mismatch" makes me think that maybe the
squeeze()
isn't executed properly or in time. This works:So it looks to me like some lazy evaluation is going awry when
open_rasterio
is involved, in this case.Anything which forces a
compute()
beforereindex_like
in this case seems to make the problem go away, like callingda
in the console,print(da)
after opening the .tif, etc.Interestingly, I can't easily inspect it, because inspecting makes the problem go away!
Expected Output
A succesfully reindexed DataArray.
Output of
xr.show_versions()
The text was updated successfully, but these errors were encountered: