From bbe4da2897abb0dff56fed23be94962c9512f63b Mon Sep 17 00:00:00 2001 From: jbusecke Date: Fri, 25 Jan 2019 18:02:42 -0500 Subject: [PATCH] adjusted to upstream changes in nc-time-axis --- xarray/plot/plot.py | 54 +++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index 7d5e0ba5eb8..f88a15d4ae1 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -22,7 +22,7 @@ import_matplotlib_pyplot, label_from_attrs) try: - from nc_time_axis import CalendarDateTime + import nc_time_axis nc_axis_available = True except ImportError: nc_axis_available = False @@ -49,7 +49,12 @@ def _ensure_plottable(*args): # hacky other_types = [datetime] if nc_axis_available: - other_types.append(CalendarDateTime) + try: + from cftime import datetime as cftime_datetime + other_types.append(cftime_datetime) + except ImportError: + print('Could not import cftime') + for x in args: if not (_valid_numpy_subdtype(np.array(x), numpy_types) @@ -108,24 +113,24 @@ def _line_facetgrid(darray, row=None, col=None, hue=None, return g.map_dataarray_line(hue=hue, **kwargs) -def _convert_cftime_data(values): - converted = [CalendarDateTime(v, v.calendar) for v in values] - return converted +# def _convert_cftime_data(values): +# converted = [CalendarDateTime(v, v.calendar) for v in values] +# return converted -def _convert_all_cftime(da): - try: - from cftime import datetime as cftime_datetime - except ImportError: - raise ImportError('cftime package missing') - da = da.copy() - # find the dim that has a cftime datatype - dims = set(da.dims) - cftime_dims = [d for d in dims if isinstance(da[d].data.ravel()[0], - cftime_datetime)] - for cd in cftime_dims: - da[cd].data = _convert_cftime_data(da[cd].data) - return da +# def _convert_all_cftime(da): +# try: +# from cftime import datetime as cftime_datetime +# except ImportError: +# raise ImportError('cftime package missing') +# da = da.copy() +# # find the dim that has a cftime datatype +# dims = set(da.dims) +# cftime_dims = [d for d in dims if isinstance(da[d].data.ravel()[0], +# cftime_datetime)] +# for cd in cftime_dims: +# da[cd].data = _convert_cftime_data(da[cd].data) +# return da def plot(darray, row=None, col=None, col_wrap=None, ax=None, hue=None, @@ -168,15 +173,12 @@ def plot(darray, row=None, col=None, col_wrap=None, ax=None, hue=None, """ darray = darray.squeeze() - - # If I am not mistaken, this did check only if there are cftime.datetime - # objects in the actual data, not dims. - # Correction below - + # Unsure about this. If I read correctly the commented line tests if + # cftime datetimes are in the data, not the dims. I assume we want to check + # the dims? if any([contains_cftime_datetimes(darray[dim]) for dim in darray.dims]): - if nc_axis_available: - darray = _convert_all_cftime(darray) - else: + # if contains_cftime_datetimes(darray): + if not nc_axis_available: raise ImportError( 'Built-in plotting of arrays of cftime.datetime objects or ' 'arrays indexed by cftime.datetime objects requires the '