Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Aug 21, 2024
1 parent c2360a8 commit d9674a6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tests/e3sm_diags/driver/utils/test_dataset_xr.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,11 @@ def test_returns_climo_dataset_using_climo_of_time_series_files(self):
ds = Dataset(parameter, data_type="ref")

result = ds.get_climo_dataset("ts", "ANN")
# Since the data is not sub-monthly, the first time coord (2001-01-01)
# is dropped when subsetting with the middle of the month (2000-01-15).
expected = self.ds_ts.isel(time=slice(1, 4))

expected = self.ds_ts.copy()
expected["time"].data[:] = np.array(
[
cftime.DatetimeGregorian(2000, 1, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 2, 15, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 3, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2001, 1, 16, 12, 0, 0, 0, has_year_zero=False),
Expand Down Expand Up @@ -1190,11 +1190,10 @@ def test_returns_time_series_dataset_using_file(self):

result = ds.get_time_series_dataset("ts")

# Since the data is not sub-monthly, the first time coord (2001-01-01)
# is dropped when subsetting with the middle of the month (2000-01-15).
expected = self.ds_ts.isel(time=slice(1, 4))
expected = self.ds_ts.copy()
expected["time"].data[:] = np.array(
[
cftime.DatetimeGregorian(2000, 1, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 2, 15, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 3, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2001, 1, 16, 12, 0, 0, 0, has_year_zero=False),
Expand Down Expand Up @@ -1248,9 +1247,10 @@ def test_returns_time_series_dataset_using_derived_var(self):
ds = Dataset(parameter, data_type="ref")

result = ds.get_time_series_dataset("PRECT")
expected = ds_pr.sel(time=slice("2000-02-01", "2001-01-01"))
expected = ds_pr.copy()
expected["time"].data[:] = np.array(
[
cftime.DatetimeGregorian(2000, 1, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 2, 15, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 3, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2001, 1, 16, 12, 0, 0, 0, has_year_zero=False),
Expand Down Expand Up @@ -1287,10 +1287,11 @@ def test_returns_time_series_dataset_using_derived_var_directly_from_dataset(sel

result = ds.get_time_series_dataset("PRECST")
expected = ds_precst.copy()
expected = ds_precst.sel(time=slice("2000-02-01", "2001-01-01"))
expected = ds_precst.copy()
expected["PRECST"].attrs["units"] = "mm/s"
expected["time"].data[:] = np.array(
[
cftime.DatetimeGregorian(2000, 1, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 2, 15, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 3, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2001, 1, 16, 12, 0, 0, 0, has_year_zero=False),
Expand Down Expand Up @@ -1341,9 +1342,10 @@ def test_returns_time_series_dataset_with_centered_time_if_non_sub_monthly_data(
ds.is_sub_monthly = False

result = ds.get_time_series_dataset("ts")
expected = self.ds_ts.isel(time=slice(1, 4))
expected = self.ds_ts.copy()
expected["time"].data[:] = np.array(
[
cftime.DatetimeGregorian(2000, 1, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 2, 15, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 3, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2001, 1, 16, 12, 0, 0, 0, has_year_zero=False),
Expand All @@ -1367,11 +1369,11 @@ def test_returns_time_series_dataset_using_file_with_ref_name_prepended(self):
ds = Dataset(parameter, data_type="ref")

result = ds.get_time_series_dataset("ts")
# Since the data is not sub-monthly, the first time coord (2001-01-01)
# is dropped when subsetting with the middle of the month (2000-01-15).
expected = ds_ts.isel(time=slice(1, 4))

expected = ds_ts.copy()
expected["time"].data[:] = np.array(
[
cftime.DatetimeGregorian(2000, 1, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 2, 15, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2000, 3, 16, 12, 0, 0, 0, has_year_zero=False),
cftime.DatetimeGregorian(2001, 1, 16, 12, 0, 0, 0, has_year_zero=False),
Expand Down

0 comments on commit d9674a6

Please sign in to comment.