コード例 #1
0
 def test_decodeBigEscape(self):
     for x in xrange(10):
         if py3compat.PY3:
             base = '\u00e5'.encode('utf-8')
         else:
             base = "\xc3\xa5"
         quote = py3compat.str_to_bytes("\"")
         input = quote + (base * 1024 * 1024 * 2) + quote
         output = ujson.decode(input)
コード例 #2
0
ファイル: period.py プロジェクト: stefanv/pandas
    def asfreq(self, freq=None, how='E'):
        how = _validate_end_alias(how)

        base1, mult1 = _gfc(self.freq)

        if isinstance(freq, basestring):
            base2, mult2 = _gfc(freq)
        else:
            base2, mult2 = freq

        new_data = lib.period_asfreq_arr(self.values, base1, mult1,
                                         base2, mult2,
                                         py3compat.str_to_bytes(how))

        return PeriodIndex(new_data, freq=freq)
コード例 #3
0
ファイル: period.py プロジェクト: stefanv/pandas
    def asfreq(self, freq=None, how='E'):
        """

        Parameters
        ----------
        freq :
        how :

        Returns
        -------
        resampled : Period
        """
        how = _validate_end_alias(how)
        base1, mult1 = _gfc(self.freq)
        base2, mult2 = _gfc(freq)

        new_ordinal = lib.period_asfreq(self.ordinal, base1, mult1,
                                        base2, mult2, py3compat.str_to_bytes(how))

        return Period(new_ordinal, (base2, mult2))
コード例 #4
0
ファイル: period.py プロジェクト: stefanv/pandas
    def __new__(cls, data=None,
                freq=None, start=None, end=None, periods=None,
                copy=False, name=None):

        if isinstance(freq, Period):
            freq = freq.freq
        else:
            freq = _freq_mod.get_standard_freq(freq)

        if data is None:
            subarr, freq = _get_ordinal_range(start, end, periods, freq)
            subarr = subarr.view(cls)
            subarr.name = name
            subarr.freq = freq

            return subarr

        if not isinstance(data, np.ndarray):
            if np.isscalar(data):
                raise ValueError('PeriodIndex() must be called with a '
                                 'collection of some kind, %s was passed'
                                 % repr(data))

            elif isinstance(data, Period):
                raise ValueError('Data must be array of dates, strings, '
                                 'or Period objects')

            # other iterable of some kind
            if not isinstance(data, (list, tuple)):
                data = list(data)

            try:
                data = np.array(data, dtype='i8')
            except:
                data = np.array(data, dtype='O')

            if freq is None and len(data) > 0:
                freq = getattr(data[0], 'freq', None)

            if freq is None:
                raise ValueError(('freq not specified and cannot be inferred '
                                  'from first element'))

            data = _period_unbox_array(data, check=freq)
        else:
            if isinstance(data, PeriodIndex):
                if freq is None or freq == data.freq:
                    freq = data.freq
                    data = data.values
                else:
                    base1, mult1 = _gfc(data.freq)
                    base2, mult2 = _gfc(freq)
                    how = py3compat.str_to_bytes('E')
                    data = lib.period_asfreq_arr(data.values, base1, mult1,
                                                 base2, mult2, how)
            else:
                if freq is None and len(data) > 0:
                    freq = getattr(data[0], 'freq')

                if freq is None:
                    raise ValueError(('freq not specified and cannot be '
                                      'inferred from first element'))

                if data.dtype == np.datetime64:
                    data = dt64arr_to_periodarr(data, freq)
                elif data.dtype == np.int64:
                    pass
                else:
                    try:
                        data = data.astype('i8')
                    except:
                        data = data.astype('O')
                        data = _period_unbox_array(data, check=freq)

        data = np.array(data, dtype=np.int64, copy=False)

        if (data <= 0).any():
            raise ValueError("Found illegal (<= 0) values in data")

        subarr = data.view(cls)
        subarr.name = name
        subarr.freq = freq

        return subarr