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 Mar 6, 2023
1 parent 81bb84d commit fa087b7
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 @@ -581,7 +581,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 @@ -619,7 +619,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 @@ -633,7 +633,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 @@ -670,7 +670,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 @@ -822,7 +822,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 @@ -835,28 +835,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 @@ -872,13 +870,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 @@ -1160,7 +1157,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 @@ -1202,7 +1199,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 @@ -1215,7 +1212,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 @@ -1257,7 +1254,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 @@ -1378,7 +1375,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 @@ -1836,7 +1833,7 @@ def test_weighted_seasonal_departures_with_DJF(self):
result = ds.temporal.departures(
"ts",
"season",
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
)
expected = ds.copy()
expected["ts"] = xr.DataArray(
Expand All @@ -1853,7 +1850,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 @@ -1871,7 +1868,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()
expected["ts"] = xr.DataArray(
Expand All @@ -1888,7 +1885,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 @@ -1925,7 +1922,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()
expected["ts"] = xr.DataArray(
Expand All @@ -1942,7 +1939,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 @@ -3128,7 +3125,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 @@ -3144,7 +3141,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 @@ -3156,7 +3153,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 @@ -3168,7 +3165,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 @@ -3194,7 +3191,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,
},
)
Loading

0 comments on commit fa087b7

Please sign in to comment.