set the data from this selection (and convert to the correct dtype
        if we can)

def convert(self, values, nan_rep, encoding, errors):
        """set the data from this selection (and convert to the correct dtype
        if we can)
        """

        # values is a recarray
        if values.dtype.fields is not None:
            values = values[self.cname]

        self.set_data(values)

        # use the meta if needed
        meta = _ensure_decoded(self.meta)

        # convert to the correct dtype
        if self.dtype is not None:
            dtype = _ensure_decoded(self.dtype)

            # reverse converts
            if dtype == 'datetime64':

                # recreate with tz if indicated
                self.data = _set_tz(self.data, self.tz, coerce=True)

            elif dtype == 'timedelta64':
                self.data = np.asarray(self.data, dtype='m8[ns]')
            elif dtype == 'date':
                try:
                    self.data = np.asarray(
                        [date.fromordinal(v) for v in self.data], dtype=object)
                except ValueError:
                    self.data = np.asarray(
                        [date.fromtimestamp(v) for v in self.data],
                        dtype=object)
            elif dtype == 'datetime':
                self.data = np.asarray(
                    [datetime.fromtimestamp(v) for v in self.data],
                    dtype=object)

            elif meta == 'category':

                # we have a categorical
                categories = self.metadata
                codes = self.data.ravel()

                # if we have stored a NaN in the categories
                # then strip it; in theory we could have BOTH
                # -1s in the codes and nulls :<
                if categories is None:
                    # Handle case of NaN-only categorical columns in which case
                    # the categories are an empty array; when this is stored,
                    # pytables cannot write a zero-len array, so on readback
                    # the categories would be None and `read_hdf()` would fail.
                    categories = Index([], dtype=np.float64)
                else:
                    mask = isna(categories)
                    if mask.any():
                        categories = categories[~mask]
                        codes[codes != -1] -= mask.astype(int).cumsum().values

                self.data = Categorical.from_codes(codes,
                                                   categories=categories,
                                                   ordered=self.ordered)

            else:

                try:
                    self.data = self.data.astype(dtype, copy=False)
                except TypeError:
                    self.data = self.data.astype('O', copy=False)

        # convert nans / decode
        if _ensure_decoded(self.kind) == 'string':
            self.data = _unconvert_string_array(
                self.data, nan_rep=nan_rep, encoding=encoding, errors=errors)

        return self