Repository navigation
If join='exact', raise an error for non-aligned objects - #1330
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. |
alignnow supportsjoin='exact', which raisesxarray.AlignmentErrorinstead 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