From 82f3c21e9c1c259c8b57039bd7c19c941eea6c9a Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Sat, 21 Sep 2024 21:22:23 -0600 Subject: [PATCH] Add skeleton tests --- xarray/tests/test_groupby.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index dff1fc61313..3949049f6a9 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -11,7 +11,7 @@ from packaging.version import Version import xarray as xr -from xarray import DataArray, Dataset, Variable +from xarray import DataArray, Dataset, Variable, cftime_range from xarray.core.alignment import broadcast from xarray.core.groupby import _consolidate_slices from xarray.core.types import InterpOptions, ResampleCompatible @@ -19,6 +19,7 @@ BinGrouper, EncodedGroups, Grouper, + SeasonResampler, TimeResampler, UniqueGrouper, season_to_month_tuple, @@ -2944,6 +2945,24 @@ def test_season_to_month_tuple(): ) +def test_season_resampler(): + time = cftime_range("2001-01-01", "2002-12-30", freq="D", calendar="360_day") + da = DataArray(np.ones(time.size), dims="time", coords={"time": time}) + + # through resample + da.resample(time=SeasonResampler(["DJF", "MAM", "JJA", "SON"])).sum() + + # through groupby + da.groupby(time=SeasonResampler(["DJF", "MAM", "JJA", "SON"])).sum() + + # skip september + da.groupby(time=SeasonResampler(["DJF", "MAM", "JJA", "ON"])).sum() + + # overlapping + with pytest.raises(ValueError): + da.groupby(time=SeasonResampler(["DJFM", "MAMJ", "JJAS", "SOND"])).sum() + + # Possible property tests # 1. lambda x: x # 2. grouped-reduce on unique coords is identical to array