Skip to content

Commit

Permalink
Add tests for monthly pivots
Browse files Browse the repository at this point in the history
This shows the current behavior, to be changed by the following commit.
  • Loading branch information
victorlin committed Mar 7, 2023
1 parent 797af0d commit b22a308
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,45 @@ def test_get_pivots_by_invalid_unit():
with pytest.raises(ValueError, match=r".*invalid_unit.*is not supported.*"):
pivots = get_pivots(observations=[], pivot_interval=1, start_date=2015.0, end_date=2016.0, pivot_interval_units="invalid_unit")


@pytest.mark.parametrize(
"start, end, expected_pivots",
[
(
"2022-01-01",
"2022-04-01",
("2022-01-01", "2022-02-01", "2022-03-01", "2022-04-01")
),
(
"2022-01-31",
"2022-03-31",
("2022-02-28", "2022-03-31")
),
(
"2022-01-31",
"2022-04-30",
("2022-02-28", "2022-03-30", "2022-04-30")
),
(
"2022-01-30",
"2022-04-30",
("2022-02-28", "2022-03-30", "2022-04-30")
),
]
)
def test_get_pivots_on_month_boundaries(start, end, expected_pivots):
"""Get pivots where the start/end dates are on month boundaries.
"""
pivots = get_pivots(
observations=[],
pivot_interval=1,
start_date=numeric_date(start),
end_date=numeric_date(end),
pivot_interval_units="months"
)
assert len(pivots) == len(expected_pivots)
assert np.allclose(pivots, [numeric_date(date) for date in expected_pivots], rtol=0, atol=1e-4)

#
# Test KDE frequency estimation for trees
#
Expand Down

0 comments on commit b22a308

Please sign in to comment.