Exemplo n.º 1
0
    def astype(self, dtype, copy=True):
        if is_interval_dtype(dtype):
            from pandas import IntervalIndex

            return IntervalIndex(np.array(self))
        elif is_categorical_dtype(dtype):
            # GH 18630
            dtype = self.dtype.update_dtype(dtype)
            if dtype == self.dtype:
                return self.copy() if copy else self

        return Index.astype(self, dtype=dtype, copy=copy)
Exemplo n.º 2
0
 def astype(self, dtype, copy=True):
     with rewrite_exception("IntervalArray", type(self).__name__):
         new_values = self._values.astype(dtype, copy=copy)
     if is_interval_dtype(new_values.dtype):
         return self._shallow_copy(new_values)
     return Index.astype(self, dtype, copy=copy)