Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning Day.delta is deprecated #713

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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