<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ensure_is_date_object(x):
 """ Ensure input represents a valid date and return the corresponding `datetime.date` object. Valid inputs: - string of the form "YYYY-MM-DD" - dt.date object - pd.Timestamp of the form "YYYY-MM-DD 00:00:00" with freq='D' (as is generated by pd.date_range()) """

    error_msg = f"Cannot convert input to date object: {x} (type: {type(x)})"

    if isinstance(x, dt.date):
        if isinstance(x, pd.Timestamp):
            if x.freq != 'D':
                raise TohuDateError("Pandas Timestamp must have freq='D' set. Got: freq={x.freq!r}")
            elif pd.Timestamp(x.date()) == x:
                return x.date()
            else:
                raise TohuDateError(error_msg)
        elif isinstance(x, dt.datetime):
            raise TohuDateError(error_msg)
        else:
            return x
    elif isinstance(x, str):
        return parse_date_string(x)
    else:
        raise TohuDateError(error_msg)