Skip to content

Alignment fails when multiple indexes are set along one common dimension #7695

Closed
@dmkriete

Description

@dmkriete

What happened?

I am trying to use xarray's smart broadcasting to do computation with two DataArrays, one of which has two indexes set for one of its dimensions. When taking the difference between these two DataArrays, I receive an error saying there are conflicting indexes.

What did you expect to happen?

I expected the computation to return a DataArray with all the original dimensions, coordinates, and indexes

Minimal Complete Verifiable Example

import numpy as np
import xarray as xr

ds = xr.Dataset(data_vars={"signal": xr.DataArray(np.zeros((3, 2)), dims=("time", "position"), coords={"time": [12, 13, 14]})})
ds = ds.assign_coords(time_relative=(ds.time - 12))
ds = ds.set_xindex("time_relative")

da = xr.DataArray(np.zeros(2), dims="position")

ds.signal - da  # Error occurs here

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.

Relevant log output

ValueError: cannot re-index or align objects with conflicting indexes found for the following dimensions: 'time' (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

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.10.9 | packaged by conda-forge | (main, Feb 2 2023, 20:14:58) [MSC v.1929 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 85 Stepping 0, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: ('de_DE', 'cp1252')
libhdf5: 1.12.2
libnetcdf: 4.9.1

xarray: 2023.3.0
pandas: 1.5.3
numpy: 1.24.2
scipy: 1.10.0
netCDF4: 1.6.2
pydap: None
h5netcdf: None
h5py: 3.8.0
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.7.0
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 67.6.1
pip: 23.0.1
conda: None
pytest: None
mypy: None
IPython: 8.11.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions