in src/smjsindustry/finance/utils.py [0:0]
def _get_freq_label_by_quarter(date_value: str) -> str:
"""Gets frequency label for the date value which is aggregated by quarter.
Args:
date_value (str): The date value.
Returns:
str: The date value aggregated by quarter.
"""
if bool(re.match(r"^\d{4}Q\d{1,2}$", date_value)):
return date_value
if not bool(re.match(r"^\d{4}-\d{1,2}(-\d{1,2})?$", date_value)):
raise ValueError("Date needs to be in yyyy-mm-dd or yyyy-mm format when freq is Q")
ts = pd.Timestamp(date_value)
return "{}Q{}".format(ts.year, ts.quarter)