From 0e7c92c701bc7a426404fcf5559397f9781f9e80 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Thu, 1 Jul 2021 06:47:12 +0200 Subject: [PATCH] Test test_missing.py without cftime installed (#5556) * Test missing without cftime * Update test_missing.py * Update test_missing.py * try importing cftime * Update test_missing.py * Update test_missing.py * Update test_missing.py * move calender list to init, import from there * Update test_cftime_offsets.py * undo test_missing changes for now * Revert "undo test_missing changes for now" This reverts commit 6b13cd435fab4332f8d690df56abe36ca85c6372. --- xarray/tests/__init__.py | 12 ++++++++++++ xarray/tests/test_cftime_offsets.py | 13 +------------ xarray/tests/test_missing.py | 8 ++++++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/xarray/tests/__init__.py b/xarray/tests/__init__.py index 64fdbca2c2c..9029dc1c621 100644 --- a/xarray/tests/__init__.py +++ b/xarray/tests/__init__.py @@ -229,3 +229,15 @@ def create_test_data(seed=None, add_attrs=True): obj.encoding = {"foo": "bar"} assert all(obj.data.flags.writeable for obj in obj.variables.values()) return obj + + +_CFTIME_CALENDARS = [ + "365_day", + "360_day", + "julian", + "all_leap", + "366_day", + "gregorian", + "proleptic_gregorian", + "standard", +] diff --git a/xarray/tests/test_cftime_offsets.py b/xarray/tests/test_cftime_offsets.py index cdac9a2d002..6d2d9907627 100644 --- a/xarray/tests/test_cftime_offsets.py +++ b/xarray/tests/test_cftime_offsets.py @@ -26,22 +26,11 @@ to_cftime_datetime, to_offset, ) +from xarray.tests import _CFTIME_CALENDARS cftime = pytest.importorskip("cftime") -_CFTIME_CALENDARS = [ - "365_day", - "360_day", - "julian", - "all_leap", - "366_day", - "gregorian", - "proleptic_gregorian", - "standard", -] - - def _id_func(param): """Called on each parameter passed to pytest.mark.parametrize""" return str(param) diff --git a/xarray/tests/test_missing.py b/xarray/tests/test_missing.py index e4c74b40ec0..e2dfac04222 100644 --- a/xarray/tests/test_missing.py +++ b/xarray/tests/test_missing.py @@ -14,6 +14,7 @@ ) from xarray.core.pycompat import dask_array_type from xarray.tests import ( + _CFTIME_CALENDARS, assert_allclose, assert_array_equal, assert_equal, @@ -23,7 +24,6 @@ requires_dask, requires_scipy, ) -from xarray.tests.test_cftime_offsets import _CFTIME_CALENDARS @pytest.fixture @@ -542,6 +542,7 @@ def test_get_clean_interp_index_dt(cf_da, calendar, freq): np.testing.assert_array_equal(gi, si) +@requires_cftime def test_get_clean_interp_index_potential_overflow(): da = xr.DataArray( [0, 1, 2], @@ -592,7 +593,10 @@ def test_interpolate_na_max_gap_errors(da_time): @requires_bottleneck -@pytest.mark.parametrize("time_range_func", [pd.date_range, xr.cftime_range]) +@pytest.mark.parametrize( + "time_range_func", + [pd.date_range, pytest.param(xr.cftime_range, marks=requires_cftime)], +) @pytest.mark.parametrize("transform", [lambda x: x, lambda x: x.to_dataset(name="a")]) @pytest.mark.parametrize( "max_gap", ["3H", np.timedelta64(3, "h"), pd.to_timedelta("3H")]