Skip to content

Commit

Permalink
Extract _calculate_departures() method
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Aug 30, 2024
1 parent 0d56ed5 commit 4c3845d
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 73 deletions.
60 changes: 30 additions & 30 deletions tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_averages_for_yearly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

# Test unweighted averages
result = ds.temporal.average("ts", weighted=False)
Expand All @@ -139,7 +139,7 @@ def test_averages_for_yearly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_averages_for_monthly_time_series(self):
# Set up dataset
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_averages_for_daily_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

# Test unweighted averages
result = ds.temporal.average("ts", weighted=False)
Expand All @@ -310,7 +310,7 @@ def test_averages_for_daily_time_series(self):
"weighted": "False",
},
)
assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_averages_for_hourly_time_series(self):
ds = xr.Dataset(
Expand Down Expand Up @@ -378,7 +378,7 @@ def test_averages_for_hourly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

# Test unweighted averages
result = ds.temporal.average("ts", weighted=False)
Expand All @@ -396,7 +396,7 @@ def test_averages_for_hourly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class TestGroupAverage:
Expand Down Expand Up @@ -619,7 +619,7 @@ def test_weighted_seasonal_averages_with_DJF_and_drop_incomplete_seasons(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons(
self,
Expand Down Expand Up @@ -670,7 +670,7 @@ def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_averages_with_JFD(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_weighted_seasonal_averages_with_JFD(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_custom_seasonal_averages(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -787,7 +787,7 @@ def test_weighted_custom_seasonal_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_raises_error_with_incorrect_custom_seasons_argument(self):
# Test raises error with non-3 letter strings
Expand Down Expand Up @@ -873,7 +873,7 @@ def test_weighted_monthly_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_monthly_averages_with_masked_data(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -924,7 +924,7 @@ def test_weighted_monthly_averages_with_masked_data(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_averages(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -967,7 +967,7 @@ def test_weighted_daily_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_hourly_averages(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1011,7 +1011,7 @@ def test_weighted_hourly_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class TestClimatology:
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def test_subsets_climatology_based_on_reference_period(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_climatology_with_DJF(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def test_weighted_seasonal_climatology_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

@requires_dask
def test_chunked_weighted_seasonal_climatology_with_DJF(self):
Expand Down Expand Up @@ -1214,7 +1214,7 @@ def test_chunked_weighted_seasonal_climatology_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_climatology_with_JFD(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1265,7 +1265,7 @@ def test_weighted_seasonal_climatology_with_JFD(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_custom_seasonal_climatology(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1328,7 +1328,7 @@ def test_weighted_custom_seasonal_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_monthly_climatology(self):
result = self.ds.temporal.climatology("ts", "month")
Expand Down Expand Up @@ -1391,7 +1391,7 @@ def test_weighted_monthly_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_monthly_climatology(self):
result = self.ds.temporal.climatology("ts", "month", weighted=False)
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def test_unweighted_monthly_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_climatology(self):
result = self.ds.temporal.climatology("ts", "day", weighted=True)
Expand Down Expand Up @@ -1515,7 +1515,7 @@ def test_weighted_daily_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_climatology_drops_leap_days_with_matching_calendar(self):
time = xr.DataArray(
Expand Down Expand Up @@ -1606,7 +1606,7 @@ def test_weighted_daily_climatology_drops_leap_days_with_matching_calendar(self)
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_daily_climatology(self):
result = self.ds.temporal.climatology("ts", "day", weighted=False)
Expand Down Expand Up @@ -1668,7 +1668,7 @@ def test_unweighted_daily_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class TestDepartures:
Expand Down Expand Up @@ -1895,7 +1895,7 @@ def test_monthly_departures_relative_to_climatology_reference_period_with_same_o
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_departures_with_DJF(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1945,7 +1945,7 @@ def test_weighted_seasonal_departures_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -2021,7 +2021,7 @@ def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
dims=["time_original"],
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_seasonal_departures_with_DJF(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -2071,7 +2071,7 @@ def test_unweighted_seasonal_departures_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_seasonal_departures_with_JFD(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -2121,7 +2121,7 @@ def test_unweighted_seasonal_departures_with_JFD(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_departures_drops_leap_days_with_matching_calendar(self):
time = xr.DataArray(
Expand Down Expand Up @@ -2214,7 +2214,7 @@ def test_weighted_daily_departures_drops_leap_days_with_matching_calendar(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class Test_GetWeights:
Expand Down
Loading

0 comments on commit 4c3845d

Please sign in to comment.