pydata / pydata/xarray

Exact alignment should allow missing dimension coordinates

Open
#2,283 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Code Sample, a copy-pastable example if possible
import xarray as xr
xr.align(xr.DataArray([1, 2, 3], dims='x'),
         xr.DataArray([1, 2, 3], dims='x', coords=[[0, 1, 2]]),
         join='exact')
Problem description

This currently results in an error, but a missing index of size 3 does not actually conflict:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-1d63d3512fb6> in <module>()
      1 xr.align(xr.DataArray([1, 2, 3], dims='x'),
      2          xr.DataArray([1, 2, 3], dims='x', coords=[[0, 1, 2]]),
----> 3          join='exact')

/usr/local/lib/python3.6/dist-packages/xarray/core/alignment.py in align(*objects, **kwargs)
    129                     raise ValueError(
    130                         'indexes along dimension {!r} are not equal'
--> 131                         .format(dim))
    132                 index = joiner(matching_indexes)
    133                 joined_indexes[dim] = index

ValueError: indexes along dimension 'x' are not equal

This surfaced as an issue on StackOverflow: https://stackoverflow.com/questions/51308962/computing-matrix-vector-multiplication-for-each-time-point-in-two-dataarrays

Expected Output

Both output arrays should end up with the x coordinate from the input that has it, like the output of the above expression if join='inner':

(<xarray.DataArray (x: 3)>
 array([1, 2, 3])
 Coordinates:
   * x        (x) int64 0 1 2, <xarray.DataArray (x: 3)>
 array([1, 2, 3])
 Coordinates:
   * x        (x) int64 0 1 2)
Output of xr.show_versions()
INSTALLED VERSIONS ------------------ commit: None python: 3.6.3.final.0 python-bits: 64 OS: Linux OS-release: 4.14.33+ machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

xarray: 0.10.7
pandas: 0.22.0
numpy: 1.14.5
scipy: 0.19.1
netCDF4: None
h5netcdf: None
h5py: 2.8.0
Nio: None
zarr: None
bottleneck: None
cyordereddict: None
dask: None
distributed: None
matplotlib: 2.1.2
cartopy: None
seaborn: 0.7.1
setuptools: 39.1.0
pip: 10.0.1
conda: None
pytest: None
IPython: 5.5.0
sphinx: None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the alignment implementation behind xr.align and reproduce the provided join='exact' example. Check how missing dimension indexes are compared, then verify that both arrays receive the existing x coordinate without raising an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.