Commit f1732d03 authored by Niklas Selke's avatar Niklas Selke
Browse files

The 'check_sampling' function now raises a 'ValueError' if there is any...

The 'check_sampling' function now raises a 'ValueError' if there is any problem with the given 'sampling' argument.
parent 6ea37fc3
......@@ -20,19 +20,27 @@ from toarstats import stats
from toarstats.stats_utils import CLIMATIC_ZONE, RSTAGS, SEASON_DICT
SAMPLING_METHODS = ",".join(RSTAGS).replace("seasonal",
"seasonal,vegseason").split(",")
def check_sampling(sampling_in):
"""Check the given sampling argument.
:param sampling_in: the given sampling argument
:return: The processed sampling argument or None if there was a
problem while processing the given sampling argument
:raises ValueError: raised if the given sampling argument is not a
string or is not recognized
:return: The given sampling argument with any leading and trailing
whitespace removed
"""
if not isinstance(sampling_in, str):
return None
raise ValueError("The sampling argument must be a string")
sampling_out = sampling_in.strip()
if sampling_out not in RSTAGS | {"vegseason"}:
return None
if sampling_out not in SAMPLING_METHODS:
raise ValueError("The sampling argument must be one of"
f" {SAMPLING_METHODS}")
return sampling_out
......
Supports Markdown
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