diff --git a/augur/frequency_estimators.py b/augur/frequency_estimators.py index 1c5117419..92206003b 100644 --- a/augur/frequency_estimators.py +++ b/augur/frequency_estimators.py @@ -79,7 +79,7 @@ def get_pivots(observations, pivot_interval, start_date=None, end_date=None, piv pivot = end while pivot >= start: pivots.appendleft(pivot) - pivot = pivot - delta + pivot = end - delta * len(pivots) pivots = np.array([numeric_date(pivot) for pivot in pivots]) diff --git a/tests/test_frequencies.py b/tests/test_frequencies.py index 8d8365907..04abcdbc6 100644 --- a/tests/test_frequencies.py +++ b/tests/test_frequencies.py @@ -150,17 +150,23 @@ def test_get_pivots_by_invalid_unit(): ( "2022-01-31", "2022-03-31", - ("2022-02-28", "2022-03-31") + ("2022-01-31", "2022-02-28", "2022-03-31") ), + # Note that Jan 31 to Apr 30 gives the same amount of pivot points as + # Jan 31 to Mar 31. ( "2022-01-31", "2022-04-30", ("2022-02-28", "2022-03-30", "2022-04-30") ), + # However, in practice, the interval is more likely to be Jan 30 to Apr + # 30 as long as the start date is calculated relative to the end date + # (i.e. start date = 3 months before Apr 30 = Jan 30). + # That interval includes an additional pivot point as expected. ( "2022-01-30", "2022-04-30", - ("2022-02-28", "2022-03-30", "2022-04-30") + ("2022-01-30", "2022-02-28", "2022-03-30", "2022-04-30") ), ] )