Skip to content

Commit

Permalink
Add test to cover missing line in _drop_incomplete_season
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Apr 4, 2024
1 parent 74c136c commit 8262a8a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def test_averages_for_monthly_time_series(self):
)

xr.testing.assert_allclose(result, expected)
assert result.ts.attrs == expected.ts.attrs

# Test unweighted averages
result = ds.temporal.average("ts", weighted=False)
Expand All @@ -227,6 +228,7 @@ def test_averages_for_monthly_time_series(self):
},
)
xr.testing.assert_allclose(result, expected)
assert result.ts.attrs == expected.ts.attrs

def test_averages_for_daily_time_series(self):
ds = xr.Dataset(
Expand Down Expand Up @@ -819,6 +821,68 @@ def test_weighted_custom_seasonal_averages(self):

xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_averages_with_custom_seasons_and_all_complete_seasons(
self,
):
ds = self.ds.copy()
ds["time"].values[:] = np.array(
[
"2000-01-16T12:00:00.000000000",
"2000-02-15T12:00:00.000000000",
"2000-03-16T12:00:00.000000000",
"2000-06-16T00:00:00.000000000",
"2000-09-16T00:00:00.000000000",
],
dtype="datetime64[ns]",
)

result = ds.temporal.group_average(
"ts",
"season",
season_config={
"custom_seasons": [["Jan", "Mar", "Jun"], ["Feb", "Sep"]],
"drop_incomplete_seasons": True,
},
)
expected = ds.copy()
expected = expected.drop_dims("time")
expected["ts"] = xr.DataArray(
name="ts",
data=np.array([[[1.34065934]], [[1.47457627]]]),
coords={
"lat": expected.lat,
"lon": expected.lon,
"time": xr.DataArray(
data=np.array(
[
cftime.DatetimeGregorian(2000, 3, 1),
cftime.DatetimeGregorian(2000, 9, 1),
],
),
dims=["time"],
attrs={
"axis": "T",
"long_name": "time",
"standard_name": "time",
"bounds": "time_bnds",
},
),
},
dims=["time", "lat", "lon"],
attrs={
"test_attr": "test",
"operation": "temporal_avg",
"mode": "group_average",
"freq": "season",
"weighted": "True",
"drop_incomplete_seasons": "True",
"custom_seasons": ["JanMarJun", "FebSep"],
},
)

xr.testing.assert_allclose(result, expected)
assert result.ts.attrs == expected.ts.attrs

def test_weighted_custom_seasonal_averages_drops_incomplete_seasons(self):
ds = self.ds.copy()
ds["time"].values[:] = np.array(
Expand Down Expand Up @@ -2244,6 +2308,7 @@ def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
)

xr.testing.assert_allclose(result, expected)
assert result.ts.attrs == expected.ts.attrs

def test_unweighted_seasonal_departures_with_DJF(self):
ds = self.ds.copy()
Expand Down

0 comments on commit 8262a8a

Please sign in to comment.