Skip to content
Snippets Groups Projects
Commit 5ec70fa3 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Handle weekly frequency

parent 88735f9d
No related branches found
No related tags found
No related merge requests found
......@@ -92,7 +92,8 @@ def norm_period(period_str, freq):
'2015-05'
"""
assert freq in ("A", "D", "M", "Q", "H"), "Unknown freq = {}".format(freq)
if freq not in ("A", "D", "M", "Q", "H", "W"):
raise ValueError(f"Unknown freq = {freq!r} for {period_str!r})
# Annual
if freq == "A":
......@@ -120,6 +121,13 @@ def norm_period(period_str, freq):
assert m, "Incorrect monthly period [{}]".format(period_str)
return period_str
# Weekly
if freq == "W":
m = WEEK_RE.match(period_str)
if not m:
raise ValueError(f"Incorrect weekly period {period_str!r}")
return f"{m.group(1)}-W{m.group(2).zfill(2)}"
# Daily
if freq == "D":
m = DAY_RE.match(period_str)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment