Skip to content

Commit 0e7c92c

Browse files
authored
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 6b13cd4.
1 parent c5dbe98 commit 0e7c92c

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

xarray/tests/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,15 @@ def create_test_data(seed=None, add_attrs=True):
229229
obj.encoding = {"foo": "bar"}
230230
assert all(obj.data.flags.writeable for obj in obj.variables.values())
231231
return obj
232+
233+
234+
_CFTIME_CALENDARS = [
235+
"365_day",
236+
"360_day",
237+
"julian",
238+
"all_leap",
239+
"366_day",
240+
"gregorian",
241+
"proleptic_gregorian",
242+
"standard",
243+
]

xarray/tests/test_cftime_offsets.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,11 @@
2626
to_cftime_datetime,
2727
to_offset,
2828
)
29+
from xarray.tests import _CFTIME_CALENDARS
2930

3031
cftime = pytest.importorskip("cftime")
3132

3233

33-
_CFTIME_CALENDARS = [
34-
"365_day",
35-
"360_day",
36-
"julian",
37-
"all_leap",
38-
"366_day",
39-
"gregorian",
40-
"proleptic_gregorian",
41-
"standard",
42-
]
43-
44-
4534
def _id_func(param):
4635
"""Called on each parameter passed to pytest.mark.parametrize"""
4736
return str(param)

xarray/tests/test_missing.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from xarray.core.pycompat import dask_array_type
1616
from xarray.tests import (
17+
_CFTIME_CALENDARS,
1718
assert_allclose,
1819
assert_array_equal,
1920
assert_equal,
@@ -23,7 +24,6 @@
2324
requires_dask,
2425
requires_scipy,
2526
)
26-
from xarray.tests.test_cftime_offsets import _CFTIME_CALENDARS
2727

2828

2929
@pytest.fixture
@@ -542,6 +542,7 @@ def test_get_clean_interp_index_dt(cf_da, calendar, freq):
542542
np.testing.assert_array_equal(gi, si)
543543

544544

545+
@requires_cftime
545546
def test_get_clean_interp_index_potential_overflow():
546547
da = xr.DataArray(
547548
[0, 1, 2],
@@ -592,7 +593,10 @@ def test_interpolate_na_max_gap_errors(da_time):
592593

593594

594595
@requires_bottleneck
595-
@pytest.mark.parametrize("time_range_func", [pd.date_range, xr.cftime_range])
596+
@pytest.mark.parametrize(
597+
"time_range_func",
598+
[pd.date_range, pytest.param(xr.cftime_range, marks=requires_cftime)],
599+
)
596600
@pytest.mark.parametrize("transform", [lambda x: x, lambda x: x.to_dataset(name="a")])
597601
@pytest.mark.parametrize(
598602
"max_gap", ["3H", np.timedelta64(3, "h"), pd.to_timedelta("3H")]

0 commit comments

Comments
 (0)