Skip to content

Make compat="override" more strict. #10094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dcherian opened this issue Mar 3, 2025 · 1 comment
Open

Make compat="override" more strict. #10094

dcherian opened this issue Mar 3, 2025 · 1 comment
Labels
bug topic-combine combine/concat/merge

Comments

@dcherian
Copy link
Contributor

dcherian commented Mar 3, 2025

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
@dcherian dcherian added bug needs triage Issue that has not been reviewed by xarray team member labels Mar 3, 2025
@dcherian dcherian added topic-combine combine/concat/merge and removed needs triage Issue that has not been reviewed by xarray team member labels Mar 3, 2025
@jsignell
Copy link
Contributor

I was just looking at this one and I'm not sure I agree with the proposal. From the description of override it seems clear that the first object is just blindly used:

- "override": skip comparing and pick variable from first dataset

I think doing any checks between variables on subsequent objects kind of undermines the usefulness of override

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug topic-combine combine/concat/merge
Projects
None yet
Development

No branches or pull requests

2 participants