|
19 | 19 | decode_cf,
|
20 | 20 | )
|
21 | 21 | from xarray.coders import CFDatetimeCoder, CFTimedeltaCoder
|
22 |
| -from xarray.coding.times import _STANDARD_CALENDARS as _STANDARD_CALENDARS_UNSORTED |
23 | 22 | from xarray.coding.times import (
|
24 | 23 | _encode_datetime_with_cftime,
|
25 | 24 | _netcdf_to_numpy_timeunit,
|
|
41 | 40 | from xarray.core.utils import is_duck_dask_array
|
42 | 41 | from xarray.testing import assert_equal, assert_identical
|
43 | 42 | from xarray.tests import (
|
| 43 | + _ALL_CALENDARS, |
| 44 | + _NON_STANDARD_CALENDARS, |
| 45 | + _STANDARD_CALENDAR_NAMES, |
| 46 | + _STANDARD_CALENDARS, |
44 | 47 | DuckArrayWrapper,
|
45 | 48 | FirstElementAccessibleArray,
|
| 49 | + _all_cftime_date_types, |
46 | 50 | arm_xfail,
|
47 | 51 | assert_array_equal,
|
48 | 52 | assert_duckarray_allclose,
|
|
53 | 57 | requires_dask,
|
54 | 58 | )
|
55 | 59 |
|
56 |
| -_NON_STANDARD_CALENDARS_SET = { |
57 |
| - "noleap", |
58 |
| - "365_day", |
59 |
| - "360_day", |
60 |
| - "julian", |
61 |
| - "all_leap", |
62 |
| - "366_day", |
63 |
| -} |
64 |
| -_STANDARD_CALENDARS = sorted(_STANDARD_CALENDARS_UNSORTED) |
65 |
| -_ALL_CALENDARS = sorted(_NON_STANDARD_CALENDARS_SET.union(_STANDARD_CALENDARS)) |
66 |
| -_NON_STANDARD_CALENDARS = sorted(_NON_STANDARD_CALENDARS_SET) |
67 | 60 | _CF_DATETIME_NUM_DATES_UNITS = [
|
68 | 61 | (np.arange(10), "days since 2000-01-01", "s"),
|
69 | 62 | (np.arange(10).astype("float64"), "days since 2000-01-01", "s"),
|
|
99 | 92 | _CF_DATETIME_TESTS = [
|
100 | 93 | num_dates_units + (calendar,)
|
101 | 94 | for num_dates_units, calendar in product(
|
102 |
| - _CF_DATETIME_NUM_DATES_UNITS, _STANDARD_CALENDARS |
| 95 | + _CF_DATETIME_NUM_DATES_UNITS, _STANDARD_CALENDAR_NAMES |
103 | 96 | )
|
104 | 97 | ]
|
105 | 98 |
|
106 | 99 |
|
107 |
| -def _all_cftime_date_types(): |
108 |
| - import cftime |
109 |
| - |
110 |
| - return { |
111 |
| - "noleap": cftime.DatetimeNoLeap, |
112 |
| - "365_day": cftime.DatetimeNoLeap, |
113 |
| - "360_day": cftime.Datetime360Day, |
114 |
| - "julian": cftime.DatetimeJulian, |
115 |
| - "all_leap": cftime.DatetimeAllLeap, |
116 |
| - "366_day": cftime.DatetimeAllLeap, |
117 |
| - "gregorian": cftime.DatetimeGregorian, |
118 |
| - "proleptic_gregorian": cftime.DatetimeProlepticGregorian, |
119 |
| - } |
120 |
| - |
121 |
| - |
122 | 100 | @requires_cftime
|
123 | 101 | @pytest.mark.filterwarnings("ignore:Ambiguous reference date string")
|
124 | 102 | @pytest.mark.filterwarnings("ignore:Times can't be serialized faithfully")
|
@@ -734,13 +712,13 @@ def test_decode_cf(calendar, time_unit: PDDatetimeUnitOptions) -> None:
|
734 | 712 | ds[v].attrs["units"] = "days since 2001-01-01"
|
735 | 713 | ds[v].attrs["calendar"] = calendar
|
736 | 714 |
|
737 |
| - if not has_cftime and calendar not in _STANDARD_CALENDARS: |
| 715 | + if not has_cftime and calendar not in _STANDARD_CALENDAR_NAMES: |
738 | 716 | with pytest.raises(ValueError):
|
739 | 717 | ds = decode_cf(ds)
|
740 | 718 | else:
|
741 | 719 | ds = decode_cf(ds, decode_times=CFDatetimeCoder(time_unit=time_unit))
|
742 | 720 |
|
743 |
| - if calendar not in _STANDARD_CALENDARS: |
| 721 | + if calendar not in _STANDARD_CALENDAR_NAMES: |
744 | 722 | assert ds.test.dtype == np.dtype("O")
|
745 | 723 | else:
|
746 | 724 | assert ds.test.dtype == np.dtype(f"=M8[{time_unit}]")
|
@@ -1085,7 +1063,7 @@ def test_decode_ambiguous_time_warns(calendar) -> None:
|
1085 | 1063 |
|
1086 | 1064 | # we don't decode non-standard calendards with
|
1087 | 1065 | # pandas so expect no warning will be emitted
|
1088 |
| - is_standard_calendar = calendar in _STANDARD_CALENDARS |
| 1066 | + is_standard_calendar = calendar in _STANDARD_CALENDAR_NAMES |
1089 | 1067 |
|
1090 | 1068 | dates = [1, 2, 3]
|
1091 | 1069 | units = "days since 1-1-1"
|
@@ -1954,7 +1932,7 @@ def test_duck_array_decode_times(calendar) -> None:
|
1954 | 1932 | decoded = conventions.decode_cf_variable(
|
1955 | 1933 | "foo", var, decode_times=CFDatetimeCoder(use_cftime=None)
|
1956 | 1934 | )
|
1957 |
| - if calendar not in _STANDARD_CALENDARS: |
| 1935 | + if calendar not in _STANDARD_CALENDAR_NAMES: |
1958 | 1936 | assert decoded.dtype == np.dtype("O")
|
1959 | 1937 | else:
|
1960 | 1938 | assert decoded.dtype == np.dtype("=M8[ns]")
|
|
0 commit comments