pydata / pydata/xarray

Make `compat="override"` more strict.

Open
#10,094 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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

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 at xr.merge and the combining functions that implement compat="override"; reproduce both argument orders from the issue. Add a regression test covering variables with mismatched ndim and verify existing override behavior remains unchanged for matching-dimensional variables.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.