Repository navigation
Raise in combine_by_coords when dataset coordinates overlap - #11957
Open
tushar-mahalya wants to merge 5 commits into
Open
tushar-mahalya wants to merge 5 commits into
tushar-mahalya wants to merge 5 commits into
Conversation
…ydata#7189) The final monotonic check accepts repeated values, so datasets with coordinates like [0, 1] and [1, 2] were concatenated into [0, 1, 1, 2]. Raise a ValueError when the combined index has duplicates that were not present in the individual datasets.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
combine_by_coordsorders the datasets by their first coordinate value and then checks that the combined index is monotonic. That check accepts equal neighbouring values, so when two datasets share a boundary label, e.g.x=[0, 1]andx=[1, 2], they are concatenated intox=[0, 1, 1, 2]without any warning. The same happens throughopen_mfdatasetwith two files whose time ranges overlap by one step, which is how I'd expect most people to hit it. Overlaps of two or more labels already raise, because the result isn't monotonic, so only the single-label case slipped through.The fix adds a check after the concat in
_combine_single_variable_hypercube: if the combined index has duplicates but every input index along that dimension was unique, it raises aValueErrorsaying the datasets overlap and suggesting dropping the overlapping labels first (e.g. withpreprocess).On warning versus error: in #7189 a warning first was suggested in case someone relies on this. I went with an error because the result has duplicate labels, which isn't a usable combined index, and it makes the one-label overlap consistent with the larger overlaps that already raise. The case mentioned there as possibly relied upon, inputs that already contain repeated labels, is left alone: the check is skipped whenever any input has repeated labels. The downside is that something like
[0, 0, 1]+[1, 2]still isn't caught. Catching it would mean comparing tile boundaries, which felt like more change than this needed. Happy to switch to a warning if you'd prefer that.Tests cover ascending and descending 1-D overlaps, a 2-D DataArray overlap on a shared timestamp, and that repeated labels within each dataset still combine as before. The three overlap tests fail on main and pass here. I ran
test_combine.py,test_concat.py,test_merge.pyandtest_datatree.pylocally (554 passed). In the wider-k "mfdataset or combine_by_coords"run, the only failures are the h5netcdfopen_mfdatasettests, which fail on main too because h5py isn't installed in my environment.Checklist
whats-new.rstAI Disclosure
Tools: Claude Code (Claude Sonnet for the fix and tests, Claude Opus for review). I asked it to find an open xarray bug without an existing PR and fix it with a regression test and a whats-new entry; it picked combine_by_coords allows one overlapping coordinate value, but not more than one #7189. I reviewed the diff and the reasoning above.