diff --git a/ci/requirements-py37-windows.yml b/ci/requirements-py37-windows.yml index 24a7f556b2c..fb4b97cde7c 100644 --- a/ci/requirements-py37-windows.yml +++ b/ci/requirements-py37-windows.yml @@ -4,6 +4,7 @@ channels: dependencies: - python=3.7 - cftime + - nc-time-axis - dask - distributed - h5py diff --git a/ci/requirements-py37.yml b/ci/requirements-py37.yml index 1a98e6b285c..4f4d2b1728b 100644 --- a/ci/requirements-py37.yml +++ b/ci/requirements-py37.yml @@ -4,6 +4,7 @@ channels: dependencies: - python=3.7 - cftime + - nc-time-axis - dask - distributed - h5py diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index f05a3edd823..d0f4e57afff 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -10,7 +10,7 @@ import numpy as np import pandas as pd -from .facetgrid import FacetGrid +from .facetgrid import _easy_facetgrid from .utils import ( _add_colorbar, _ensure_plottable, _infer_interval_breaks, _infer_xy_labels, _interval_to_double_bound_points, _interval_to_mid_points, @@ -102,26 +102,6 @@ def _infer_line_data(darray, x, y, hue): return xplt, yplt, hueplt, xlabel, ylabel, huelabel -# 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 plot(darray, row=None, col=None, col_wrap=None, ax=None, hue=None, rtol=0.01, subplot_kws=None, **kwargs): """ diff --git a/xarray/tests/__init__.py b/xarray/tests/__init__.py index a7eafa92bd7..9d571ff07f9 100644 --- a/xarray/tests/__init__.py +++ b/xarray/tests/__init__.py @@ -63,6 +63,7 @@ def LooseVersion(vstring): has_pynio, requires_pynio = _importorskip('Nio') has_pseudonetcdf, requires_pseudonetcdf = _importorskip('PseudoNetCDF') has_cftime, requires_cftime = _importorskip('cftime') +has_nc_time_axis, requires_nc_time_axis = _importorskip('nc_time_axis') has_cftime_1_0_2_1, requires_cftime_1_0_2_1 = _importorskip( 'cftime', minversion='1.0.2.1') has_dask, requires_dask = _importorskip('dask') diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 96f88b7bfb3..fcacf5ec1c5 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -17,7 +17,9 @@ from . import ( assert_array_equal, assert_equal, raises_regex, requires_cftime, - requires_matplotlib, requires_matplotlib2, requires_seaborn) + requires_matplotlib, requires_matplotlib2, requires_seaborn, + requires_nc_time_axis, + ) # import mpl and change the backend before other mpl imports try: @@ -1828,6 +1830,31 @@ def test_datetime_line_plot(self): self.darray.plot.line() +@requires_nc_time_axis +@requires_cftime +class TestCFDatetimePlot(PlotTestCase): + @pytest.fixture(autouse=True) + def setUp(self): + ''' + Create a DataArray with a time-axis that contains cftime.datetime64 + objects. + ''' + month = np.arange(1, 13, 1) + data = np.sin(2 * np.pi * month / 12.0) + + darray = DataArray(data, dims=['time']) + darray.coords['time'] = xr.cftime_range(start='2017', + periods=12, + freq='1M', + calendar='noleap') + + self.darray = darray + + def test_cfdatetime_line_plot(self): + # test if line plot raises no Exception + self.darray.plot.line() + + @requires_seaborn def test_import_seaborn_no_warning(): # GH1633