Skip to content

Commit 879af59

Browse files
committed
cftime tests
1 parent 8773faf commit 879af59

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

xarray/groupers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,8 @@ def factorize(self, group: T_Group) -> EncodedGroups:
876876

877877
# all years and seasons
878878
def get_label(year, season):
879-
month = season_tuples[season][0]
880-
return f"{year}-{month}-01"
879+
month, *_ = season_tuples[season]
880+
return f"{year}-{month:02d}-01"
881881

882882
unique_codes = np.arange(len(unique_coord))
883883
valid_season_mask = season_label != ""

xarray/tests/test_groupby.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -3182,23 +3182,39 @@ def test_season_resampling_raises_unsorted_seasons(self, seasons):
31823182
with pytest.raises(ValueError, match="sort"):
31833183
da.resample(time=SeasonResampler(seasons))
31843184

3185-
# TODO: drop_incomplete
3186-
@requires_cftime
3185+
@pytest.mark.parametrize(
3186+
"use_cftime",
3187+
[
3188+
pytest.param(
3189+
True, marks=pytest.mark.skipif(not has_cftime, reason="no cftime")
3190+
),
3191+
False,
3192+
],
3193+
)
31873194
@pytest.mark.parametrize("drop_incomplete", [True, False])
31883195
@pytest.mark.parametrize(
31893196
"seasons",
31903197
[
31913198
pytest.param(["DJF", "MAM", "JJA", "SON"], id="standard"),
3199+
pytest.param(["NDJ", "FMA", "MJJ", "ASO"], id="nov-first"),
31923200
pytest.param(["MAM", "JJA", "SON", "DJF"], id="standard-diff-order"),
31933201
pytest.param(["JFM", "AMJ", "JAS", "OND"], id="december-same-year"),
31943202
pytest.param(["DJF", "MAM", "JJA", "ON"], id="skip-september"),
31953203
pytest.param(["JJAS"], id="jjas-only"),
31963204
pytest.param(["MAM", "JJA", "SON", "DJF"], id="different-order"),
31973205
],
31983206
)
3199-
def test_season_resampler(self, seasons: list[str], drop_incomplete: bool) -> None:
3207+
def test_season_resampler(
3208+
self, seasons: list[str], drop_incomplete: bool, use_cftime: bool
3209+
) -> None:
32003210
calendar = "standard"
3201-
time = date_range("2001-01-01", "2002-12-30", freq="D", calendar=calendar)
3211+
time = date_range(
3212+
"2001-01-01",
3213+
"2002-12-30",
3214+
freq="D",
3215+
calendar=calendar,
3216+
use_cftime=use_cftime,
3217+
)
32023218
da = DataArray(np.ones(time.size), dims="time", coords={"time": time})
32033219
counts = da.resample(time="ME").count()
32043220

@@ -3239,7 +3255,7 @@ def test_season_resampler(self, seasons: list[str], drop_incomplete: bool) -> No
32393255
# we construct expected in the standard calendar
32403256
xr.DataArray(expected_vals, dims="time", coords={"time": expected_time})
32413257
# and then convert to the expected calendar,
3242-
.convert_calendar(calendar, align_on="date")
3258+
.convert_calendar(calendar, align_on="date", use_cftime=use_cftime)
32433259
# and finally sort since DJF will be out-of-order
32443260
.sortby("time")
32453261
)

0 commit comments

Comments
 (0)