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
Conditional import of the DatetimeAccessor due to xarray update #1078
Conversation
Since the DatetimeAccessor is only imported to add # If DatetimeAccessor does not have a strftime (xarray <0.12.2), monkey patch one in
try:
from xarray.core.accessors import DatetimeAccessor
if not hasattr(DatetimeAccessor, 'strftime'):
def strftime(self, date_format):
"""Format time as a string."""
import pandas as pd
values = self._obj.data
values_as_series = pd.Series(values.ravel())
strs = values_as_series.dt.strftime(date_format)
return strs.values.reshape(values.shape)
DatetimeAccessor.strftime = strftime
except ImportError:
pass This would also remove the Python 2.7 problem with |
Should we just vendor this as well and include it in #1079 for sake of consistency? Seems like that would be better than having multiple methods for importing things from I didn't realize there were issues with |
I could be mistaken, but I don't think we can vendor in |
Gotcha - that makes sense. Glad you know your way around this code to help me. I'll make the changes you suggested and push it up. |
backend API of xarray v0.12.2. Fixes Unidata#1077. Updated import method per @jthielen's suggestion
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.
Thanks for knocking out a fix so quickly.
Failures are just SkewT. Merging... |
Xarray v0.12.2 changed how it handles the DatetimeAccessor. As a result, a conditional import is needed to allow for Python 2 support. This can be updated back to a simple import of the v0.12.2 version once Python 2 support is dropped.
Fixes #1077.