Skip to content

Make compat="override" more strict. #10094

Open
@dcherian

Description

@dcherian

What happened?

The compat="override" option in the various combining functions, avoids comparing values for compatibility and simply picks the first occurence of a variable, and inserts it in the result.

This can be dangerous if the values are of differing dimensionality:

ds1 = xr.Dataset({"x": 0})
ds2 = xr.Dataset({"x": ("y", [0, 0])})

Now the dimensionality of x in the output depends on the order of arguments (example below).

I propose that compat="override" at least check that ndim is the same for a variable across all provided objects.

Example

xr.merge([ds1, ds2], compat="override")
<xarray.Dataset> Size: 8B
Dimensions:  ()
Data variables:
    x        int64 8B 0
xr.merge([ds2, ds1], compat="override")
<xarray.Dataset> Size: 16B
Dimensions:  (y: 2)
Dimensions without coordinates: y
Data variables:
    x        (y) int64 16B 0 0

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