-
-
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
Improve alignment checks #10251
Conversation
- Improved error messages (more context) - Simplified logic - Removed overly restrictive checks that caused alignment to fail when multiple indexes are set along common dimensions
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
nice test!
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.
LGTM. Thanks!
This is an important fix, so lets merge ASAP.
The doctest simply needs updating from ValueError to AlignmentError AFAICT
@@ -837,7 +837,7 @@ def align( | |||
>>> a, b = xr.align(x, y, join="exact") | |||
Traceback (most recent call last): | |||
... | |||
AlignmentError: cannot align objects with join='exact' ... | |||
xarray.structure.alignment.AlignmentError: cannot align objects with join='exact' ... |
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 for MergeError
, etc.)
* main: Fix convert calendar on non-temporal data in datasets (pydata#10268) BinGrouper: reduce indirection (pydata#10270) Fix reduction by subset of grouper dimensions (pydata#10258) Shorten text repr for ``DataTree`` (pydata#10139) Fix benchmarks runners (pydata#10265) Fix infinite recursion when calling `np.fix` (pydata#10248) BinGrouper: Support setting labels when provided with IntervalIndex (pydata#10259) Avoid stacking when grouping by chunked array (pydata#10254) Improve alignment checks (pydata#10251) Update how-to-add-new-backend.rst (pydata#10240) Support extension array indexes (pydata#9671) Switch documentation to pydata-sphinx-theme (pydata#8708) Bump codecov/codecov-action from 5.4.0 to 5.4.2 in the actions group (pydata#10239)
xindex
s on a dim aren't alignable #9474xindex
causes.where
to fail #9697whats-new.rst
api.rst
The alignment error
was not user-friendly, sometimes too restrictive and is now gone!
The examples in the issues linked above now work, i.e., it is possible to align objects with multiple indexes found along one or more common dimensions as long as either
Index.reindex_like()
called for each index return matching indexers along those dimensionsSo this example works too:
A more user-friendly error is raised when indexers don't match: