Skip to content

Commit

Permalink
Fix warning Day.delta is deprecated (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencalje committed Mar 29, 2024
1 parent 67392f3 commit c7b2b58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pastas/timeseries_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ def _frequency_is_supported(freq: str) -> str:
"""
offset = to_offset(freq)
if not hasattr(offset, "delta"):
try:
Timedelta(offset)
except:
msg = "Frequency {} not supported.".format(freq)
logger.error(msg)
raise ValueError(msg)
if offset.n == 1:
freq = offset.name
else:
if offset.n == 1:
freq = offset.name
else:
freq = str(offset.n) + offset.name
freq = str(offset.n) + offset.name
return freq


Expand All @@ -87,9 +88,9 @@ def _get_stress_dt(freq: str) -> float:
return None
# Get the frequency string and multiplier
offset = to_offset(freq)
if hasattr(offset, "delta"):
try:
dt = Timedelta(offset) / Timedelta(1, "D")
else:
except:
num = offset.n
freq = offset._prefix
if freq in ["A", "Y", "AS", "YS", "BA", "BY", "BAS", "BYS"]:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_timeseries_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pastas as ps
import pytest


def test_frequency_is_supported():
ps.ts._frequency_is_supported("D")
ps.ts._frequency_is_supported("7D")
with pytest.raises(Exception):
ps.ts._frequency_is_supported("SMS")


def test_get_stress_dt():
assert ps.ts._get_stress_dt("D") == 1.0
assert ps.ts._get_stress_dt("7D") == 7.0
assert ps.ts._get_stress_dt("W") == 7.0
assert ps.ts._get_stress_dt("SMS") == 15.0

0 comments on commit c7b2b58

Please sign in to comment.