Skip to content

combine_by_coords can succed when it shouldn't #4824

@mathause

Description

@mathause

What happened:

combine_by_coords can succeed when it should not - depending on the name of the dimensions (which determines the order of operations in combine_by_coords).

What you expected to happen:

  • I think it should throw an error in both cases.

Minimal Complete Verifiable Example:

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 + 1e-6
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))

ds

returns:

<xarray.Dataset>
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

Thus lat is interlaced - it don't think combine_by_coords should do this. If you set

x_name = "lat"

and run the example again, it returns:

ValueError: Resulting object does not have monotonic global indexes along dimension x

Anything else we need to know?:

if not all(index.equals(indexes[0]) for index in indexes[1:]):

cc @dcherian @TomNicholas

Environment:

Output of xr.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions