def cast(self, d):
        """
        Cast a single value to a :class:`datetime.date`.

        :param date_format:
            An optional :func:`datetime.strptime` format string for parsing
            datetimes in this column.
        :returns:
            :class:`datetime.date` or :code:`None`.
        """
        if type(d) is date or d is None:
            return d
        elif isinstance(d, six.string_types):
            d = d.strip()

            if d.lower() in self.null_values:
                return None
        else:
            raise CastError('Can not parse value "%s" as date.' % d)

        if self.date_format:
            try:
                dt = datetime.strptime(d, self.date_format)
            except:
                raise CastError('Value "%s" does not match date format.' % d)

            return dt.date()

        value, ctx = self.parser.parseDT(d, sourceTime=ZERO_DT)

        if ctx.hasDate and not ctx.hasTime:
            return value.date()

        try:
            dt = isodate.parse_date(d)

            if ctx.hasTime:
                raise ValueError('isodate.parse_date discarded a time component')

            return dt
        except (isodate.ISO8601Error, __HOLE__):
            pass

        raise CastError('Can not parse value "%s" as date.' % d)
dataset/ETHPy150Open wireservice/agate/agate/data_types/date.py/Date.cast