-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve alignment checks #10251
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
Merged
Merged
Improve alignment checks #10251
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83f3197
refactor alignment index conflict checks
benbovy 12adc01
add AlignmentError exception class
benbovy 835ae4b
add tests
benbovy 0b44cbd
Merge branch 'main' into improve-alignment-checks
dcherian fbf0af6
Fix CI
dcherian 7986d2d
Merge branch 'main' into improve-alignment-checks
dcherian e6424c9
update whats new
benbovy 837c970
fix doctests (custom exception class path)
benbovy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1644,6 +1644,7 @@ Exceptions | |
.. autosummary:: | ||
:toctree: generated/ | ||
|
||
AlignmentError | ||
MergeError | ||
SerializationWarning | ||
|
||
|
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
import xarray as xr | ||
from xarray import ( | ||
AlignmentError, | ||
DataArray, | ||
Dataset, | ||
IndexVariable, | ||
|
@@ -2543,6 +2544,28 @@ def test_align_indexes(self) -> None: | |
|
||
assert_identical(expected_x2, x2) | ||
|
||
def test_align_multiple_indexes_common_dim(self) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice test! |
||
a = Dataset(coords={"x": [1, 2], "xb": ("x", [3, 4])}).set_xindex("xb") | ||
b = Dataset(coords={"x": [1], "xb": ("x", [3])}).set_xindex("xb") | ||
|
||
(a2, b2) = align(a, b, join="inner") | ||
assert_identical(a2, b, check_default_indexes=False) | ||
assert_identical(b2, b, check_default_indexes=False) | ||
|
||
c = Dataset(coords={"x": [1, 3], "xb": ("x", [2, 4])}).set_xindex("xb") | ||
|
||
with pytest.raises(AlignmentError, match=".*conflicting re-indexers"): | ||
align(a, c) | ||
|
||
def test_align_conflicting_indexes(self) -> None: | ||
class CustomIndex(PandasIndex): ... | ||
|
||
a = Dataset(coords={"xb": ("x", [3, 4])}).set_xindex("xb") | ||
b = Dataset(coords={"xb": ("x", [3])}).set_xindex("xb", CustomIndex) | ||
|
||
with pytest.raises(AlignmentError, match="cannot align.*conflicting indexes"): | ||
align(a, b) | ||
|
||
def test_align_non_unique(self) -> None: | ||
x = Dataset({"foo": ("x", [3, 4, 5]), "x": [0, 0, 1]}) | ||
x1, x2 = align(x, x) | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be cleaner to later have Xarray exceptions defined in their own module
xarray.exceptions.AlignmentError
(same forMergeError
, etc.)