def date_string_to_date(p_date):
    """
    Given a date in YYYY-MM-DD, returns a Python date object. Throws a
    ValueError if the date is invalid.
    """
    result = None

    if p_date:
        parsed_date = re.match(r'(\d{4})-(\d{2})-(\d{2})', p_date)
        if parsed_date:
            result = date(
                int(parsed_date.group(1)),  # year
                int(parsed_date.group(2)),  # month
                int(parsed_date.group(3))   # day
            )
        else:
            raise ValueError

    return result
Given a date in YYYY-MM-DD, returns a Python date object. Throws a
    ValueError if the date is invalid.