Skip to content

Commit

Permalink
make periods_in_duration more lax
Browse files Browse the repository at this point in the history
  • Loading branch information
attila-balint-kul committed Feb 20, 2024
1 parent e6a98bd commit c624809
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/enfobench/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.1"
__version__ = "0.4.2"
8 changes: 2 additions & 6 deletions src/enfobench/evaluation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ def periods_in_duration(target: pd.DatetimeIndex, duration: timedelta | pd.Timed
msg = f"Duration must be one of [pd.Timedelta, timedelta, str], got {type(duration)}"
raise ValueError(msg)

if len(target.diff()[1:].unique()) != 1:
msg = f"Multiple frequencies found: '{list(target.diff()[1:].unique())}'"
raise ValueError(msg)

delta_t = target.diff()[1:].unique()[0]
periods = duration / target.diff()[1:].unique()[0]
delta_t = target[1] - target[0]
periods = duration / delta_t
if not periods.is_integer():
msg = f"Season length '{duration}' is not a multiple of the frequency '{delta_t}'"
raise ValueError(msg)
Expand Down
9 changes: 0 additions & 9 deletions tests/test_evaluations/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ def test_periods_in_duration_raises_with_wrong_types():
utils.periods_in_duration(target, 3)


def test_periods_in_duration_raises_with_multiple_frequencies():
target_1 = pd.date_range(start="2020-01-01", end="2020-01-02", freq="15T", inclusive="left")
target_2 = pd.date_range(start="2020-01-02", end="2020-01-03", freq="30T", inclusive="left")
target = pd.DatetimeIndex(np.append(target_1.values, target_2.values))

with pytest.raises(ValueError):
utils.periods_in_duration(target, "1H")


def test_periods_in_duration_raises_if_duration_is_not_multiples():
target = pd.date_range(start="2020-01-01", end="2020-02-01", freq="15T")
with pytest.raises(ValueError):
Expand Down

0 comments on commit c624809

Please sign in to comment.