Skip to content

Commit

Permalink
Replace drop_incomplete_djf with drop_incomplete_seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Apr 4, 2024
1 parent 3a53f14 commit eb21226
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 116 deletions.
57 changes: 27 additions & 30 deletions tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def test_weighted_seasonal_averages_with_DJF_and_drop_incomplete_seasons(self):
result = ds.temporal.group_average(
"ts",
"season",
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
)
expected = ds.copy()
# Drop the incomplete DJF seasons
Expand Down Expand Up @@ -615,7 +615,7 @@ def test_weighted_seasonal_averages_with_DJF_and_drop_incomplete_seasons(self):
"freq": "season",
"weighted": "True",
"dec_mode": "DJF",
"drop_incomplete_djf": "True",
"drop_incomplete_seasons": "True",
},
)

Expand All @@ -629,7 +629,7 @@ def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons
result = ds.temporal.group_average(
"ts",
"season",
season_config={"dec_mode": "DJF", "drop_incomplete_djf": False},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": False},
)
expected = ds.copy()
expected = expected.drop_dims("time")
Expand Down Expand Up @@ -666,7 +666,7 @@ def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons
"freq": "season",
"weighted": "True",
"dec_mode": "DJF",
"drop_incomplete_djf": "False",
"drop_incomplete_seasons": "False",
},
)

Expand Down Expand Up @@ -818,7 +818,7 @@ def test_weighted_custom_seasonal_averages(self):

assert result.identical(expected)

def test_weighted_seasonal_averages_drops_incomplete_seasons(self):
def test_weighted_custom_seasonal_averages_drops_incomplete_seasons(self):
ds = self.ds.copy()
ds["time"].values[:] = np.array(
[
Expand All @@ -831,28 +831,26 @@ def test_weighted_seasonal_averages_drops_incomplete_seasons(self):
dtype="datetime64[ns]",
)

custom_seasons = [
["Nov", "Dec", "Jan", "Feb", "Mar"],
]
custom_seasons = [["Nov", "Dec"], ["Feb", "Mar", "Apr"]]

result = ds.temporal.group_average(
"ts",
"season",
season_config={
"drop_incomplete_seasons": True,
"custom_seasons": custom_seasons,
# "drop_incomplete_seasons": True,
},
)
expected = ds.copy()
expected = expected.drop_dims("time")
expected["ts"] = xr.DataArray(
name="ts",
data=np.array([[[1.3933333]]]),
data=np.array([[[1.5]]]),
coords={
"lat": expected.lat,
"lon": expected.lon,
"time": xr.DataArray(
data=np.array([cftime.datetime(2001, 1, 1)], dtype=object),
data=np.array([cftime.datetime(2000, 12, 1)], dtype=object),
dims=["time"],
attrs={
"axis": "T",
Expand All @@ -868,13 +866,12 @@ def test_weighted_seasonal_averages_drops_incomplete_seasons(self):
"operation": "temporal_avg",
"mode": "group_average",
"freq": "season",
"custom_seasons": ["NovDecJanFebMar"],
"custom_seasons": ["NovDec", "FebMarApr"],
"weighted": "True",
},
)

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

def test_weighted_custom_seasonal_averages_with_seasons_spanning_calendar_years(
self,
Expand Down Expand Up @@ -1214,7 +1211,7 @@ def test_weighted_seasonal_climatology_with_DJF(self):
result = ds.temporal.climatology(
"ts",
"season",
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
)

expected = ds.copy()
Expand Down Expand Up @@ -1256,7 +1253,7 @@ def test_weighted_seasonal_climatology_with_DJF(self):
"freq": "season",
"weighted": "True",
"dec_mode": "DJF",
"drop_incomplete_djf": "True",
"drop_incomplete_seasons": "True",
},
)

Expand All @@ -1269,7 +1266,7 @@ def test_chunked_weighted_seasonal_climatology_with_DJF(self):
result = ds.temporal.climatology(
"ts",
"season",
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
)

expected = ds.copy()
Expand Down Expand Up @@ -1311,7 +1308,7 @@ def test_chunked_weighted_seasonal_climatology_with_DJF(self):
"freq": "season",
"weighted": "True",
"dec_mode": "DJF",
"drop_incomplete_djf": "True",
"drop_incomplete_seasons": "True",
},
)

Expand Down Expand Up @@ -1432,7 +1429,7 @@ def test_weighted_custom_seasonal_climatology(self):
assert result.identical(expected)

@pytest.mark.xfail
def test_weighted_custom_seasonal_climatology_with_seasons_spanning_calendar_years_and_drop_incomplete_seasons(
def test_weighted_custom_seasonal_climatology_with_seasons_spanning_calendar_years(
self,
):
ds = self.ds.copy()
Expand Down Expand Up @@ -2076,7 +2073,7 @@ def test_weighted_seasonal_departures_with_DJF(self):
"ts",
"season",
weighted=True,
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
)

expected = ds.copy()
Expand Down Expand Up @@ -2113,7 +2110,7 @@ def test_weighted_seasonal_departures_with_DJF(self):
"freq": "season",
"weighted": "True",
"dec_mode": "DJF",
"drop_incomplete_djf": "True",
"drop_incomplete_seasons": "True",
},
)

Expand All @@ -2127,7 +2124,7 @@ def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
"season",
weighted=True,
keep_weights=True,
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
)

expected = ds.copy()
Expand Down Expand Up @@ -2164,7 +2161,7 @@ def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
"freq": "season",
"weighted": "True",
"dec_mode": "DJF",
"drop_incomplete_djf": "True",
"drop_incomplete_seasons": "True",
},
)
expected["time_wts"] = xr.DataArray(
Expand Down Expand Up @@ -2202,7 +2199,7 @@ def test_unweighted_seasonal_departures_with_DJF(self):
"ts",
"season",
weighted=False,
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
)

expected = ds.copy()
Expand Down Expand Up @@ -2239,7 +2236,7 @@ def test_unweighted_seasonal_departures_with_DJF(self):
"freq": "season",
"weighted": "False",
"dec_mode": "DJF",
"drop_incomplete_djf": "True",
"drop_incomplete_seasons": "True",
},
)

Expand Down Expand Up @@ -3418,7 +3415,7 @@ def test_raises_error_with_incorrect_mode_arg(self):
weighted=True,
season_config={
"dec_mode": "DJF",
"drop_incomplete_djf": False,
"drop_incomplete_seasons": False,
"custom_seasons": None,
},
)
Expand All @@ -3434,7 +3431,7 @@ def test_raises_error_if_freq_arg_is_not_supported_by_operation(self):
weighted=True,
season_config={
"dec_mode": "DJF",
"drop_incomplete_djf": False,
"drop_incomplete_seasons": False,
"custom_seasons": None,
},
)
Expand All @@ -3446,7 +3443,7 @@ def test_raises_error_if_freq_arg_is_not_supported_by_operation(self):
weighted=True,
season_config={
"dec_mode": "DJF",
"drop_incomplete_djf": False,
"drop_incomplete_seasons": False,
"custom_seasons": None,
},
)
Expand All @@ -3458,7 +3455,7 @@ def test_raises_error_if_freq_arg_is_not_supported_by_operation(self):
weighted=True,
season_config={
"dec_mode": "DJF",
"drop_incomplete_djf": False,
"drop_incomplete_seasons": False,
"custom_seasons": None,
},
)
Expand All @@ -3484,7 +3481,7 @@ def test_raises_error_if_december_mode_is_not_supported(self):
weighted=True,
season_config={
"dec_mode": "unsupported",
"drop_incomplete_djf": False,
"drop_incomplete_seasons": False,
"custom_seasons": None,
},
)
Expand Down
Loading

0 comments on commit eb21226

Please sign in to comment.