-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
If join='exact', raise an error for non-aligned objects #1330
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
Conversation
@pydata/xarray Any thoughts on this feature? Does it seem useful to you? Does the name |
Yes, it's a nice sanity check.
Yes.
Is it worth introducing custom exception types into xarray? Seems like
Otherwise you'll probably want to change some others to |
My thought is that custom exception types make sense when the exception is effectively part of the API, though possibly it would make sense to have AlignmentError inherit from ValueError. For example, the first part of a utility function
(actually, perhaps we should write Or to log potential performance issues:
I actually think every operation that automatically aligns already goes through |
I'm thinking about some of the ones in |
Trying to understand how this relates to #1413... Does |
Yes, it does. It checks indexes for equality, and if they don't match it raises an error (rather than aligning). |
This has been sitting for a little while... @shoyer please don't let my comment keep you from merging- it was more to note that this introduces custom error types. |
`align` now supports ``join='exact'``, which raises `xarray.AlignmentError` instead of aligning when indexes to be aligned are not equal. This is useful for asserting that objects are identical instead of aligning in xarray operations. For example: ds1 = xarray.Dataset({'x': [0, 1]}) ds2 = xarray.Dataset({'x': [1, 2]}) xarray.merge([ds1, ds2], join='exact') # AlignmentError: indexes along dimension 'x' are not equal
I switched from AlignmentError -> ValueError. We can always add an AlignmentError later subclassing from ValueError if we want it. |
In it goes! Thanks everyone for your feedback. |
align
now supportsjoin='exact'
, which raisesxarray.AlignmentError
instead of aligning when indexes to be aligned are not equal.This is useful for asserting that objects are identical instead of aligning in xarray operations.
For example:
git diff upstream/master | flake8 --diff