I tried a DataArray with more than one dimension coordinate. Unfortunately xr.align fails, which disallows any arithmetic operation - even when the coords are exactly the same.
What did you expect to happen?
No response
Minimal Complete Verifiable Example
import numpy as np
import xarray as xr
data = np.arange(12).reshape(3, 4)
y = [10, 20, 30]
s = ["a", "b", "c"]
x = [1, 2, 3, 4]
da = xr.DataArray(data, dims=("y", "x"), coords={"x": x, "y": y, "s": ("y", s)})
da = da.set_xindex("s")
xr.align(da, da.y) # errors
da + da # errors
da + da.x # errors
MVCE confirmation
[ ] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
[ ] Complete example — the example is self-contained, including all data and the text of any traceback.
[ ] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
[ ] New issue — a search of GitHub Issues suggests this is not a duplicate.
[ ] Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/mathause/code/mesmer/devel/prepare_for_surfer.ipynb Cell 28 line 1
12 da = xr.DataArray(data, dims=("y", "x"), coords={"x": x, "y": y, "s": ("y", s)})
13 da = da.set_xindex("s")
---> 15 xr.align(da, da.y) # errors
17 da + da.x # errors
File ~/.conda/envs/mesmer_dev/lib/python3.9/site-packages/xarray/core/alignment.py:888, in align(join, copy, indexes, exclude, fill_value, *objects)
692 """
693 Given any number of Dataset and/or DataArray objects, returns new
694 objects with aligned indexes and dimension sizes.
ref='~/.conda/envs/mesmer_dev/lib/python3.9/site-packages/xarray/core/alignment.py:0'>0</a>;32m (...)
878
879 """
880 aligner = Aligner(
881 objects,
882 join=join,
ref='~/.conda/envs/mesmer_dev/lib/python3.9/site-packages/xarray/core/alignment.py:0'>0</a>;32m (...)
886 fill_value=fill_value,
887 )
--> 888 aligner.align()
889 return aligner.results
File ~/.conda/envs/mesmer_dev/lib/python3.9/site-packages/xarray/core/alignment.py:573, in Aligner.align(self)
571 self.find_matching_indexes()
572 self.find_matching_unindexed_dims()
--> 573 self.assert_no_index_conflict()
574 self.align_indexes()
575 self.assert_unindexed_dim_sizes_equal()
File ~/.conda/envs/mesmer_dev/lib/python3.9/site-packages/xarray/core/alignment.py:318, in Aligner.assert_no_index_conflict(self)
314 if dup:
315 items_msg = ", ".join(
316 f"{k!r} ({v} conflicting indexes)" for k, v in dup.items()
317 )
--> 318 raise ValueError(
319 "cannot re-index or align objects with conflicting indexes found for "
320 f"the following {msg}: {items_msg}\n"
321 "Conflicting indexes may occur when\n"
322 "- they relate to different sets of coordinate and/or dimension names\n"
323 "- they don't have the same type\n"
324 "- they may be used to reindex data along common dimensions"
325 )
ValueError: cannot re-index or align objects with conflicting indexes found for the following dimensions: 'y' (2 conflicting indexes)
Conflicting indexes may occur when
- they relate to different sets of coordinate and/or dimension names
- they don't have the same type
- they may be used to reindex data along common dimensions
What happened?
I tried a DataArray with more than one dimension coordinate. Unfortunately
xr.align
fails, which disallows any arithmetic operation - even when the coords are exactly the same.What did you expect to happen?
No response
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment