-
Notifications
You must be signed in to change notification settings - Fork 8
Trigger errors when coordinates don't match #46
Comments
cc @klindsay28 |
@andersy005, I am reopening this issue. I am concerned that the implementation we chose in #54 sets How can we do this without wrapping every computation in a context manager? One option is to define a function decorator: from contextlib import ContextDecorator
class xarray_setoptions(ContextDecorator):
def __init__(self, **kwargs):
self.old = xr.set_options(**kwargs).old
def __enter__(self):
return self
def __exit__(self, *exc):
xr.set_options(**self.old)
return
@xarray_setoptions(arithmetic_join="exact")
def compute_mon_climatology(dset, time_coord_name=None):
# computation This seems like a nice way to implement this feature at the function level, but it's not Python 2 compatible. We could put xr_settings_old = xr.set_options(arithmetic_join="exact").old at the top of every function, and xr.set_options(**self.old) at the bottom. @mnlevy1981, we should discuss plans for |
@matt-long I think |
I don't think |
If we could protect the class definition from python 2, I'd be okay with having |
@andersy005, I think Mike's suggestion is a good one, if the decorator is ignored. There would have to be a dummy object in py2 to import into the computational modules so as to keep these clean of version checks. |
@mnlevy1981, there's a |
I have encountered issues operating on files with lossy compression applied to coordinates. In these cases,
xarray
can do the wrong thing when applying its logic for coordinate alignment.If the coordinates don't match, it takes the 'inner' set by default:
This is seldom desired in the applications I am familiar with.
We could therefore wrap all instances where we are relying on automatic alignment in a context manager as follows.
The text was updated successfully, but these errors were encountered: