Skip to content

Commit fa087b7

Browse files
committed
Replace drop_incomplete_djf with drop_incomplete_seasons
1 parent 81bb84d commit fa087b7

File tree

2 files changed

+162
-116
lines changed

2 files changed

+162
-116
lines changed

tests/test_temporal.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def test_weighted_seasonal_averages_with_DJF_and_drop_incomplete_seasons(self):
581581
result = ds.temporal.group_average(
582582
"ts",
583583
"season",
584-
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
584+
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
585585
)
586586
expected = ds.copy()
587587
# Drop the incomplete DJF seasons
@@ -619,7 +619,7 @@ def test_weighted_seasonal_averages_with_DJF_and_drop_incomplete_seasons(self):
619619
"freq": "season",
620620
"weighted": "True",
621621
"dec_mode": "DJF",
622-
"drop_incomplete_djf": "True",
622+
"drop_incomplete_seasons": "True",
623623
},
624624
)
625625

@@ -633,7 +633,7 @@ def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons
633633
result = ds.temporal.group_average(
634634
"ts",
635635
"season",
636-
season_config={"dec_mode": "DJF", "drop_incomplete_djf": False},
636+
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": False},
637637
)
638638
expected = ds.copy()
639639
expected = expected.drop_dims("time")
@@ -670,7 +670,7 @@ def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons
670670
"freq": "season",
671671
"weighted": "True",
672672
"dec_mode": "DJF",
673-
"drop_incomplete_djf": "False",
673+
"drop_incomplete_seasons": "False",
674674
},
675675
)
676676

@@ -822,7 +822,7 @@ def test_weighted_custom_seasonal_averages(self):
822822

823823
assert result.identical(expected)
824824

825-
def test_weighted_seasonal_averages_drops_incomplete_seasons(self):
825+
def test_weighted_custom_seasonal_averages_drops_incomplete_seasons(self):
826826
ds = self.ds.copy()
827827
ds["time"].values[:] = np.array(
828828
[
@@ -835,28 +835,26 @@ def test_weighted_seasonal_averages_drops_incomplete_seasons(self):
835835
dtype="datetime64[ns]",
836836
)
837837

838-
custom_seasons = [
839-
["Nov", "Dec", "Jan", "Feb", "Mar"],
840-
]
838+
custom_seasons = [["Nov", "Dec"], ["Feb", "Mar", "Apr"]]
841839

842840
result = ds.temporal.group_average(
843841
"ts",
844842
"season",
845843
season_config={
844+
"drop_incomplete_seasons": True,
846845
"custom_seasons": custom_seasons,
847-
# "drop_incomplete_seasons": True,
848846
},
849847
)
850848
expected = ds.copy()
851849
expected = expected.drop_dims("time")
852850
expected["ts"] = xr.DataArray(
853851
name="ts",
854-
data=np.array([[[1.3933333]]]),
852+
data=np.array([[[1.5]]]),
855853
coords={
856854
"lat": expected.lat,
857855
"lon": expected.lon,
858856
"time": xr.DataArray(
859-
data=np.array([cftime.datetime(2001, 1, 1)], dtype=object),
857+
data=np.array([cftime.datetime(2000, 12, 1)], dtype=object),
860858
dims=["time"],
861859
attrs={
862860
"axis": "T",
@@ -872,13 +870,12 @@ def test_weighted_seasonal_averages_drops_incomplete_seasons(self):
872870
"operation": "temporal_avg",
873871
"mode": "group_average",
874872
"freq": "season",
875-
"custom_seasons": ["NovDecJanFebMar"],
873+
"custom_seasons": ["NovDec", "FebMarApr"],
876874
"weighted": "True",
877875
},
878876
)
879877

880-
xr.testing.assert_allclose(result, expected)
881-
assert result.ts.attrs == expected.ts.attrs
878+
assert result.identical(expected)
882879

883880
def test_weighted_custom_seasonal_averages_with_seasons_spanning_calendar_years(
884881
self,
@@ -1160,7 +1157,7 @@ def test_weighted_seasonal_climatology_with_DJF(self):
11601157
result = ds.temporal.climatology(
11611158
"ts",
11621159
"season",
1163-
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
1160+
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
11641161
)
11651162

11661163
expected = ds.copy()
@@ -1202,7 +1199,7 @@ def test_weighted_seasonal_climatology_with_DJF(self):
12021199
"freq": "season",
12031200
"weighted": "True",
12041201
"dec_mode": "DJF",
1205-
"drop_incomplete_djf": "True",
1202+
"drop_incomplete_seasons": "True",
12061203
},
12071204
)
12081205

@@ -1215,7 +1212,7 @@ def test_chunked_weighted_seasonal_climatology_with_DJF(self):
12151212
result = ds.temporal.climatology(
12161213
"ts",
12171214
"season",
1218-
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
1215+
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
12191216
)
12201217

12211218
expected = ds.copy()
@@ -1257,7 +1254,7 @@ def test_chunked_weighted_seasonal_climatology_with_DJF(self):
12571254
"freq": "season",
12581255
"weighted": "True",
12591256
"dec_mode": "DJF",
1260-
"drop_incomplete_djf": "True",
1257+
"drop_incomplete_seasons": "True",
12611258
},
12621259
)
12631260

@@ -1378,7 +1375,7 @@ def test_weighted_custom_seasonal_climatology(self):
13781375
assert result.identical(expected)
13791376

13801377
@pytest.mark.xfail
1381-
def test_weighted_custom_seasonal_climatology_with_seasons_spanning_calendar_years_and_drop_incomplete_seasons(
1378+
def test_weighted_custom_seasonal_climatology_with_seasons_spanning_calendar_years(
13821379
self,
13831380
):
13841381
ds = self.ds.copy()
@@ -1836,7 +1833,7 @@ def test_weighted_seasonal_departures_with_DJF(self):
18361833
result = ds.temporal.departures(
18371834
"ts",
18381835
"season",
1839-
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
1836+
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
18401837
)
18411838
expected = ds.copy()
18421839
expected["ts"] = xr.DataArray(
@@ -1853,7 +1850,7 @@ def test_weighted_seasonal_departures_with_DJF(self):
18531850
"freq": "season",
18541851
"weighted": "True",
18551852
"dec_mode": "DJF",
1856-
"drop_incomplete_djf": "True",
1853+
"drop_incomplete_seasons": "True",
18571854
},
18581855
)
18591856

@@ -1871,7 +1868,7 @@ def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
18711868
"season",
18721869
weighted=True,
18731870
keep_weights=True,
1874-
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
1871+
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
18751872
)
18761873
expected = ds.copy()
18771874
expected["ts"] = xr.DataArray(
@@ -1888,7 +1885,7 @@ def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
18881885
"freq": "season",
18891886
"weighted": "True",
18901887
"dec_mode": "DJF",
1891-
"drop_incomplete_djf": "True",
1888+
"drop_incomplete_seasons": "True",
18921889
},
18931890
)
18941891
expected["time_wts"] = xr.DataArray(
@@ -1925,7 +1922,7 @@ def test_unweighted_seasonal_departures_with_DJF(self):
19251922
"ts",
19261923
"season",
19271924
weighted=False,
1928-
season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},
1925+
season_config={"dec_mode": "DJF", "drop_incomplete_seasons": True},
19291926
)
19301927
expected = ds.copy()
19311928
expected["ts"] = xr.DataArray(
@@ -1942,7 +1939,7 @@ def test_unweighted_seasonal_departures_with_DJF(self):
19421939
"freq": "season",
19431940
"weighted": "False",
19441941
"dec_mode": "DJF",
1945-
"drop_incomplete_djf": "True",
1942+
"drop_incomplete_seasons": "True",
19461943
},
19471944
)
19481945

@@ -3128,7 +3125,7 @@ def test_raises_error_with_incorrect_mode_arg(self):
31283125
weighted=True,
31293126
season_config={
31303127
"dec_mode": "DJF",
3131-
"drop_incomplete_djf": False,
3128+
"drop_incomplete_seasons": False,
31323129
"custom_seasons": None,
31333130
},
31343131
)
@@ -3144,7 +3141,7 @@ def test_raises_error_if_freq_arg_is_not_supported_by_operation(self):
31443141
weighted=True,
31453142
season_config={
31463143
"dec_mode": "DJF",
3147-
"drop_incomplete_djf": False,
3144+
"drop_incomplete_seasons": False,
31483145
"custom_seasons": None,
31493146
},
31503147
)
@@ -3156,7 +3153,7 @@ def test_raises_error_if_freq_arg_is_not_supported_by_operation(self):
31563153
weighted=True,
31573154
season_config={
31583155
"dec_mode": "DJF",
3159-
"drop_incomplete_djf": False,
3156+
"drop_incomplete_seasons": False,
31603157
"custom_seasons": None,
31613158
},
31623159
)
@@ -3168,7 +3165,7 @@ def test_raises_error_if_freq_arg_is_not_supported_by_operation(self):
31683165
weighted=True,
31693166
season_config={
31703167
"dec_mode": "DJF",
3171-
"drop_incomplete_djf": False,
3168+
"drop_incomplete_seasons": False,
31723169
"custom_seasons": None,
31733170
},
31743171
)
@@ -3194,7 +3191,7 @@ def test_raises_error_if_december_mode_is_not_supported(self):
31943191
weighted=True,
31953192
season_config={
31963193
"dec_mode": "unsupported",
3197-
"drop_incomplete_djf": False,
3194+
"drop_incomplete_seasons": False,
31983195
"custom_seasons": None,
31993196
},
32003197
)

0 commit comments

Comments
 (0)