|
11 | 11 | from packaging.version import Version |
12 | 12 |
|
13 | 13 | import xarray as xr |
14 | | -from xarray import DataArray, Dataset, Variable |
| 14 | +from xarray import DataArray, Dataset, Variable, cftime_range |
15 | 15 | from xarray.core.alignment import broadcast |
16 | 16 | from xarray.core.groupby import _consolidate_slices |
17 | 17 | from xarray.core.types import InterpOptions, ResampleCompatible |
18 | 18 | from xarray.groupers import ( |
19 | 19 | BinGrouper, |
20 | 20 | EncodedGroups, |
21 | 21 | Grouper, |
| 22 | + SeasonResampler, |
22 | 23 | TimeResampler, |
23 | 24 | UniqueGrouper, |
24 | 25 | season_to_month_tuple, |
@@ -2944,6 +2945,24 @@ def test_season_to_month_tuple(): |
2944 | 2945 | ) |
2945 | 2946 |
|
2946 | 2947 |
|
| 2948 | +def test_season_resampler(): |
| 2949 | + time = cftime_range("2001-01-01", "2002-12-30", freq="D", calendar="360_day") |
| 2950 | + da = DataArray(np.ones(time.size), dims="time", coords={"time": time}) |
| 2951 | + |
| 2952 | + # through resample |
| 2953 | + da.resample(time=SeasonResampler(["DJF", "MAM", "JJA", "SON"])).sum() |
| 2954 | + |
| 2955 | + # through groupby |
| 2956 | + da.groupby(time=SeasonResampler(["DJF", "MAM", "JJA", "SON"])).sum() |
| 2957 | + |
| 2958 | + # skip september |
| 2959 | + da.groupby(time=SeasonResampler(["DJF", "MAM", "JJA", "ON"])).sum() |
| 2960 | + |
| 2961 | + # overlapping |
| 2962 | + with pytest.raises(ValueError): |
| 2963 | + da.groupby(time=SeasonResampler(["DJFM", "MAMJ", "JJAS", "SOND"])).sum() |
| 2964 | + |
| 2965 | + |
2947 | 2966 | # Possible property tests |
2948 | 2967 | # 1. lambda x: x |
2949 | 2968 | # 2. grouped-reduce on unique coords is identical to array |
|
0 commit comments