예제 #1
0
 def astype(self, dtype, copy=True):
     dtype = np.dtype(dtype)
     if is_object_dtype(dtype):
         return self.asobject
     elif is_integer_dtype(dtype):
         return Index(self.values.astype('i8', copy=copy),
                      name=self.name,
                      dtype='i8')
     raise ValueError('Cannot cast PeriodIndex to dtype %s' % dtype)
예제 #2
0
    def _sub_period(self, other):
        if self.freq != other.freq:
            msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
            raise IncompatibleFrequency(msg)

        asi8 = self.asi8
        new_data = asi8 - other.ordinal

        if self.hasnans:
            new_data = new_data.astype(np.float64)
            new_data[self._isnan] = np.nan
        # result must be Int64Index or Float64Index
        return Index(new_data, name=self.name)
예제 #3
0
파일: period.py 프로젝트: smoofra/pandas
 def astype(self, dtype, copy=True, how='start'):
     dtype = pandas_dtype(dtype)
     if is_object_dtype(dtype):
         return self.asobject
     elif is_integer_dtype(dtype):
         return Index(self.values.astype('i8', copy=copy), name=self.name,
                      dtype='i8')
     elif is_datetime64_dtype(dtype):
         return self.to_timestamp(how=how)
     elif is_datetime64tz_dtype(dtype):
         return self.to_timestamp(how=how).tz_localize(dtype.tz)
     elif is_period_dtype(dtype):
         return self.asfreq(freq=dtype.freq)
     raise ValueError('Cannot cast PeriodIndex to dtype %s' % dtype)
예제 #4
0
    def _sub_period(self, other):
        if self.freq != other.freq:
            msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
            raise IncompatibleFrequency(msg)

        if other.ordinal == tslib.iNaT:
            new_data = np.empty(len(self))
            new_data.fill(np.nan)
        else:
            asi8 = self.asi8
            new_data = asi8 - other.ordinal

            if self.hasnans:
                mask = asi8 == tslib.iNaT
                new_data = new_data.astype(np.float64)
                new_data[mask] = np.nan
        # result must be Int64Index or Float64Index
        return Index(new_data, name=self.name)
예제 #5
0
파일: period.py 프로젝트: DT021/wau
    def append(self, other):
        """
        Append a collection of Index options together

        Parameters
        ----------
        other : Index or list/tuple of indices

        Returns
        -------
        appended : Index
        """
        name = self.name
        to_concat = [self]

        if isinstance(other, (list, tuple)):
            to_concat = to_concat + list(other)
        else:
            to_concat.append(other)

        for obj in to_concat:
            if isinstance(obj, Index) and obj.name != name:
                name = None
                break

        to_concat = self._ensure_compat_concat(to_concat)

        if isinstance(to_concat[0], PeriodIndex):
            if len(set([x.freq for x in to_concat])) > 1:
                # box
                to_concat = [x.asobject.values for x in to_concat]
            else:
                cat_values = np.concatenate([x.values for x in to_concat])
                return PeriodIndex(cat_values, freq=self.freq, name=name)

        to_concat = [
            x.values if isinstance(x, Index) else x for x in to_concat
        ]
        return Index(com._concat_compat(to_concat), name=name)
예제 #6
0
파일: period.py 프로젝트: while/pandas
 def asobject(self):
     from pandas.core.index import Index
     return Index(self._box_values(self.values), dtype=object)
예제 #7
0
 def asobject(self):
     return Index(self._box_values(self.values), dtype=object)
예제 #8
0
파일: period.py 프로젝트: wakamori/pandas
 def f(self):
     base, mult = _gfc(self.freq)
     result = get_period_field_arr(alias, self._values, base)
     return Index(result, name=self.name)