Skip to content

Commit

Permalink
Add skeleton tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Sep 22, 2024
1 parent 17cc3d8 commit 82f3c21
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
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
from xarray.groupers import (
BinGrouper,
EncodedGroups,
Grouper,
SeasonResampler,
TimeResampler,
UniqueGrouper,
season_to_month_tuple,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 82f3c21

Please sign in to comment.