Skip to content

Commit 28bc4d5

Browse files
authored
Merge pull request #1375 from xylar/fix-test-warnings
Fix warnings in unit tests
2 parents 4957049 + be8c120 commit 28bc4d5

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

pcmdi_metrics/enso/lib/summary_plot_lib/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def multiportraitplot(
10161016
aspect=40,
10171017
)
10181018
cbar.ax.set_yticklabels(
1019-
["-2 $\sigma$", "-1", "MMV", "1", "2 $\sigma$"], fontdict=fontdict # noqa
1019+
[r"-2 $\sigma$", "-1", "MMV", "1", r"2 $\sigma$"], fontdict=fontdict # noqa
10201020
)
10211021
dict_arrow = dict(facecolor="k", width=8, headwidth=40, headlength=40, shrink=0.0)
10221022
dict_txt = dict(fontsize=40, rotation="vertical", ha="center", weight="bold")

tests/test_drcdm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
def create_random_precip(years, max_val=None, min_val=None):
99
# Returns array of precip along with sftlf
10-
times = xr.cftime_range(
10+
times = xr.date_range(
1111
start="{0}-01-01".format(years[0]),
1212
end="{0}-12-31".format(years[1]),
1313
freq="D",
1414
calendar="noleap",
15+
use_cftime=True,
1516
name="time",
1617
)
1718
latd = 2
@@ -36,6 +37,7 @@ def create_random_precip(years, max_val=None, min_val=None):
3637

3738
fake_ds["time"].encoding["calendar"] = "noleap"
3839
fake_ds["time"].encoding["units"] = "days since 0000-01-01"
40+
fake_ds["lat"].attrs["units"] = "degrees_north"
3941
fake_ds = fake_ds.bounds.add_missing_bounds()
4042

4143
if max_val is not None:
@@ -55,6 +57,7 @@ def create_random_precip(years, max_val=None, min_val=None):
5557
)
5658
}
5759
)
60+
sftlf["lat"].attrs["units"] = "degrees_north"
5861
sftlf = sftlf.bounds.add_missing_bounds(["X", "Y"])
5962

6063
return fake_ds, sftlf
@@ -66,11 +69,12 @@ def create_seasonal_precip(season):
6669
mos = sd[season]
6770

6871
years = [1980, 1981]
69-
times = xr.cftime_range(
72+
times = xr.date_range(
7073
start="{0}-01-01".format(years[0]),
7174
end="{0}-12-31".format(years[1]),
7275
freq="D",
7376
calendar="noleap",
77+
use_cftime=True,
7478
name="time",
7579
)
7680
latd = 2
@@ -99,6 +103,7 @@ def create_seasonal_precip(season):
99103
)
100104
fake_ds["time"].encoding["calendar"] = "noleap"
101105
fake_ds["time"].encoding["units"] = "days since 0000-01-01"
106+
fake_ds["lat"].attrs["units"] = "degrees_north"
102107
fake_ds = fake_ds.bounds.add_missing_bounds()
103108

104109
sftlf_arr = np.ones((latd, lond))
@@ -113,6 +118,7 @@ def create_seasonal_precip(season):
113118
)
114119
}
115120
)
121+
sftlf["lat"].attrs["units"] = "degrees_north"
116122
sftlf = sftlf.bounds.add_missing_bounds(["X", "Y"])
117123

118124
return fake_ds, sftlf

tests/test_extremes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
def create_random_precip(years, max_val=None, min_val=None):
88
# Returns array of precip along with covariate and sftlf
9-
times = xr.cftime_range(
9+
times = xr.date_range(
1010
start="{0}-01-01".format(years[0]),
1111
end="{0}-12-31".format(years[1]),
1212
freq="D",
1313
calendar="noleap",
14+
use_cftime=True,
1415
name="time",
1516
)
1617
latd = 2
@@ -48,6 +49,7 @@ def create_random_precip(years, max_val=None, min_val=None):
4849

4950
fake_ds["time"].encoding["calendar"] = "noleap"
5051
fake_ds["time"].encoding["units"] = "days since 0000-01-01"
52+
fake_ds["lat"].attrs["units"] = "degrees_north"
5153
fake_ds = fake_ds.bounds.add_missing_bounds()
5254

5355
if max_val is not None:
@@ -67,6 +69,7 @@ def create_random_precip(years, max_val=None, min_val=None):
6769
)
6870
}
6971
)
72+
sftlf["lat"].attrs["units"] = "degrees_north"
7073
sftlf = sftlf.bounds.add_missing_bounds(["X", "Y"])
7174

7275
return fake_ds, fake_cov, sftlf
@@ -78,11 +81,12 @@ def create_seasonal_precip(season):
7881
mos = sd[season]
7982

8083
years = [1980, 1981]
81-
times = xr.cftime_range(
84+
times = xr.date_range(
8285
start="{0}-01-01".format(years[0]),
8386
end="{0}-12-31".format(years[1]),
8487
freq="D",
8588
calendar="noleap",
89+
use_cftime=True,
8690
name="time",
8791
)
8892
latd = 2
@@ -111,6 +115,7 @@ def create_seasonal_precip(season):
111115
)
112116
fake_ds["time"].encoding["calendar"] = "noleap"
113117
fake_ds["time"].encoding["units"] = "days since 0000-01-01"
118+
fake_ds["lat"].attrs["units"] = "degrees_north"
114119
fake_ds = fake_ds.bounds.add_missing_bounds()
115120

116121
sftlf_arr = np.ones((latd, lond)) * 100
@@ -125,6 +130,7 @@ def create_seasonal_precip(season):
125130
)
126131
}
127132
)
133+
sftlf["lat"].attrs["units"] = "degrees_north"
128134
sftlf = sftlf.bounds.add_missing_bounds(["X", "Y"])
129135

130136
return fake_ds, sftlf

tests/test_qc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
@pytest.fixture
1414
def create_dataset():
1515
def _create_dataset(start_date, periods, freq, calendar="gregorian"):
16-
dates = xr.cftime_range(
17-
start_date, periods=periods, freq=freq, calendar=calendar
16+
dates = xr.date_range(
17+
start_date, periods=periods, freq=freq, calendar=calendar, use_cftime=True
1818
)
1919
return xr.Dataset({"time": dates})
2020

@@ -50,13 +50,13 @@ def test_check_daily_time_axis_missing_time_key(create_dataset):
5050
# Test check_monthly_time_axis
5151
@pytest.mark.parametrize("calendar", ["gregorian", "noleap", "360_day"])
5252
def test_check_monthly_time_axis_correct(create_dataset, calendar):
53-
ds = create_dataset("2000-01-01", 24, "M", calendar=calendar)
53+
ds = create_dataset("2000-01-01", 24, "ME", calendar=calendar)
5454
assert check_monthly_time_axis(ds) is None
5555

5656

5757
def test_check_monthly_time_axis_incorrect(create_dataset):
5858
# Test with incorrect monthly sequence
59-
ds = create_dataset("2000-01-01", 24, "2M")
59+
ds = create_dataset("2000-01-01", 24, "2ME")
6060
with pytest.raises(ValueError, match="DATA ERROR: time is not correct!"):
6161
check_monthly_time_axis(ds)
6262

@@ -68,7 +68,7 @@ def test_check_monthly_time_axis_non_datetime():
6868

6969

7070
def test_check_monthly_time_axis_missing_time_key(create_dataset):
71-
ds = create_dataset("2000-01-01", 24, "M")
71+
ds = create_dataset("2000-01-01", 24, "ME")
7272
with pytest.raises(KeyError):
7373
check_monthly_time_axis(ds, time_key="non_existent_key")
7474

tests/test_sea_ice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
def create_fake_sea_ice_ds():
88
years = [1980, 1999]
9-
times = xr.cftime_range(
9+
times = xr.date_range(
1010
start="{0}-01-01".format(years[0]),
1111
end="{0}-12-31".format(years[1]),
1212
freq="ME",
1313
calendar="noleap",
14+
use_cftime=True,
1415
name="time",
1516
)
1617
latd = 2

0 commit comments

Comments
 (0)