html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/4824#issuecomment-841244252,https://api.github.com/repos/pydata/xarray/issues/4824,841244252,MDEyOklzc3VlQ29tbWVudDg0MTI0NDI1Mg==,10194086,2021-05-14T13:28:50Z,2021-05-14T13:28:50Z,MEMBER,"I add the example from https://github.com/pydata/xarray/pull/4753#discussion_r631399543 here. I am not 100% if that is the same problem or not:
```python
def combine_by_coords_problem(name, join=""override""):
ds0 = xr.Dataset(coords={""x1"": [1, 2, 3], name: [10, 20, 30]})
ds1 = xr.Dataset(coords={""x1"": [4, 5, 6], name: [40, 50, 60]})
return xr.combine_by_coords([ds0, ds1], join=join)
combine_by_coords_problem(""x0"") # concatenates 1, 2, 3, 4, 5, 6
combine_by_coords_problem(""x2"") # concatenates 10, 20, 30, 40, 50, 60
```
with `join=`
- `""exact""`: error
- `""left"", ""right"", ""inner"", ""override""`: ambiguous result
- `""outer""`: sensible result","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,788534915
https://github.com/pydata/xarray/issues/4824#issuecomment-811309154,https://api.github.com/repos/pydata/xarray/issues/4824,811309154,MDEyOklzc3VlQ29tbWVudDgxMTMwOTE1NA==,10194086,2021-03-31T18:24:19Z,2021-03-31T18:24:19Z,MEMBER,"But then it also overrides when it should concatenate...
```python
import numpy as np
import xarray as xr
data = np.arange(5).reshape(1, 5)
x = np.arange(5)
x_name = ""lat""
da0 = xr.DataArray(data, dims=(""t"", x_name), coords={""t"": [1], x_name: x}).to_dataset(name=""a"")
x = x + 5
da1 = xr.DataArray(data, dims=(""t"", x_name), coords={""t"": [2], x_name: x}).to_dataset(name=""a"")
ds = xr.combine_by_coords((da0, da1), join=""override"")
```
out
```python
Dimensions: (lat: 5, t: 2)
Coordinates:
* lat (lat) int64 0 1 2 3 4
* t (t) int64 1 2
Data variables:
a (t, lat) int64 0 1 2 3 4 0 1 2 3 4
```
Again if we set `x_name = ""y""` the following is returned:
```python
Dimensions: (t: 1, y: 10)
Coordinates:
* t (t) int64 1
* y (y) int64 0 1 2 3 4 5 6 7 8 9
Data variables:
a (t, y) int64 0 1 2 3 4 0 1 2 3 4
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,788534915
https://github.com/pydata/xarray/issues/4824#issuecomment-771530648,https://api.github.com/repos/pydata/xarray/issues/4824,771530648,MDEyOklzc3VlQ29tbWVudDc3MTUzMDY0OA==,10194086,2021-02-02T10:19:21Z,2021-02-02T10:19:21Z,MEMBER,"Thanks for the thorough answer! Thus, we need to figure out if there is a ""bug"" in `merge` or if this has to be soved in `combine_by_coords`.
Disallowing ""ragged hypercubes"" certainly makes the problem much easier. Then we can say: ""if two coords have the same start they need to be equal"" (I think).","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,788534915
https://github.com/pydata/xarray/issues/4824#issuecomment-770848655,https://api.github.com/repos/pydata/xarray/issues/4824,770848655,MDEyOklzc3VlQ29tbWVudDc3MDg0ODY1NQ==,10194086,2021-02-01T13:15:18Z,2021-02-01T13:15:18Z,MEMBER,"`combine_by_coords` does a `merge` and a `concat` (in the `_combine_1d` [function](https://github.com/pydata/xarray/blob/5735e163bea43ec9bc3c2e640fbf25a1d4a9d0c0/xarray/core/combine.py#L240)). The order of these operations makes a difference to the result. See details.
merge leads to interlaced coords
```python
In [2]: xr.merge([da0, da1])
Out[2]:
Dimensions: (lat: 10, t: 2)
Coordinates:
* lat (lat) float64 0.0 1e-06 1.0 1.0 2.0 2.0 3.0 3.0 4.0 4.0
* t (t) int64 1 2
Data variables:
a (t, lat) float64 0.0 nan 1.0 nan 2.0 nan ... 2.0 nan 3.0 nan 4.0
```
concat leads to - well - concatenated coords
```python
xr.concat([da0, da1], dim=""lat"")
Out[5]:
Dimensions: (lat: 10, t: 2)
Coordinates:
* t (t) int64 1 2
* lat (lat) float64 0.0 1.0 2.0 3.0 4.0 1e-06 1.0 2.0 3.0 4.0
Data variables:
a (t, lat) float64 0.0 1.0 2.0 3.0 4.0 nan ... 0.0 1.0 2.0 3.0 4.0
```
Yes I think I'd be interested to fix this...
---
One question on the scope of `combine_by_coords` - consider the following example with 4 arrays (""a"" through ""d"") arranged as follows:
```
aabbb
cccdd
```
Or as `Dataset`:
```python
ds_a = xr.Dataset({""data"": ((""y"", ""x""), [[1, 2]]), ""x"": [0, 1], ""y"": [0]})
ds_b = xr.Dataset({""data"": ((""y"", ""x""), [[3, 4, 5]]), ""x"": [2, 3, 4], ""y"": [0]})
ds_c = xr.Dataset({""data"": ((""y"", ""x""), [[11, 12, 14]]), ""x"": [0, 1, 2], ""y"": [1]})
ds_d = xr.Dataset({""data"": ((""y"", ""x""), [[14, 15]]), ""x"": [3, 4], ""y"": [1]})
xr.combine_by_coords([ds_a, ds_b, ds_c, ds_d]).data
```
Should that work or not?
**Current behaviour**
Currently it yields the following:
```python
array([[ 1, 2, 3, 4, 5],
[11, 12, 14, 14, 15]])
Coordinates:
* x (x) int64 0 1 2 3 4
* y (y) int64 0 1
```
However, if `""x""` is renamed to `""z""` it fails (`""resulting coords not monotonic""`).
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,788534915