当前位置: 首页>>代码示例>>Python>>正文


Python frequencies.get_freq_code方法代码示例

本文整理汇总了Python中pandas.tseries.frequencies.get_freq_code方法的典型用法代码示例。如果您正苦于以下问题:Python frequencies.get_freq_code方法的具体用法?Python frequencies.get_freq_code怎么用?Python frequencies.get_freq_code使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.tseries.frequencies的用法示例。


在下文中一共展示了frequencies.get_freq_code方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_to_timestamp_base

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def test_get_to_timestamp_base(self):
        tsb = frequencies.get_to_timestamp_base

        assert (tsb(frequencies.get_freq_code('D')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('W')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('M')[0]) ==
                frequencies.get_freq_code('D')[0])

        assert (tsb(frequencies.get_freq_code('S')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('T')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('H')[0]) ==
                frequencies.get_freq_code('S')[0]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_frequencies.py

示例2: _beg_apply_index

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def _beg_apply_index(self, i, freq):
        """Offsets index to beginning of Period frequency"""

        off = i.to_perioddelta('D')

        from pandas.tseries.frequencies import get_freq_code
        base, mult = get_freq_code(freq)
        base_period = i.to_period(base)
        if self.n <= 0:
            # when subtracting, dates on start roll to prior
            roll = np.where(base_period.to_timestamp() == i - off,
                            self.n, self.n + 1)
        else:
            roll = self.n

        base = (base_period + roll).to_timestamp()
        return base + off 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:19,代码来源:offsets.py

示例3: _end_apply_index

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def _end_apply_index(self, i, freq):
        """Offsets index to end of Period frequency"""

        off = i.to_perioddelta('D')

        from pandas.tseries.frequencies import get_freq_code
        base, mult = get_freq_code(freq)
        base_period = i.to_period(base)
        if self.n > 0:
            # when adding, dates on end roll to next
            roll = np.where(base_period.to_timestamp(how='end') == i - off,
                            self.n, self.n - 1)
        else:
            roll = self.n

        base = (base_period + roll).to_timestamp(how='end')
        return base + off

    # way to get around weirdness with rule_code 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:21,代码来源:offsets.py

示例4: test_frequency_misc

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def test_frequency_misc(self):
        assert (resolution.get_freq_group('T') ==
                frequencies.FreqGroup.FR_MIN)

        code, stride = frequencies.get_freq_code(offsets.Hour())
        assert code == frequencies.FreqGroup.FR_HR

        code, stride = frequencies.get_freq_code((5, 'T'))
        assert code == frequencies.FreqGroup.FR_MIN
        assert stride == 5

        offset = offsets.Hour()
        result = frequencies.to_offset(offset)
        assert result == offset

        result = frequencies.to_offset((5, 'T'))
        expected = offsets.Minute(5)
        assert result == expected

        with tm.assert_raises_regex(ValueError, 'Invalid frequency'):
            frequencies.get_freq_code((5, 'baz'))

        with tm.assert_raises_regex(ValueError, 'Invalid frequency'):
            frequencies.to_offset('100foo')

        with tm.assert_raises_regex(ValueError, 'Could not evaluate'):
            frequencies.to_offset(('', '')) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:29,代码来源:test_frequencies.py

示例5: _field_accessor

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def _field_accessor(name, alias, docstring=None):
    def f(self):
        base, mult = _gfc(self.freq)
        result = get_period_field_arr(alias, self._ndarray_values, base)
        return Index(result, name=self.name)
    f.__name__ = name
    f.__doc__ = docstring
    return property(f) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:period.py

示例6: dt64arr_to_periodarr

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def dt64arr_to_periodarr(data, freq, tz):
    if data.dtype != np.dtype('M8[ns]'):
        raise ValueError('Wrong dtype: %s' % data.dtype)

    freq = Period._maybe_convert_freq(freq)
    base, mult = _gfc(freq)
    return period.dt64arr_to_periodarr(data.view('i8'), base, tz)

# --- Period index sketch 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:period.py

示例7: to_timestamp

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def to_timestamp(self, freq=None, how='start'):
        """
        Cast to DatetimeIndex

        Parameters
        ----------
        freq : string or DateOffset, optional
            Target frequency. The default is 'D' for week or longer,
            'S' otherwise
        how : {'s', 'e', 'start', 'end'}

        Returns
        -------
        DatetimeIndex
        """
        how = _validate_end_alias(how)

        if freq is None:
            base, mult = _gfc(self.freq)
            freq = frequencies.get_to_timestamp_base(base)
        else:
            freq = Period._maybe_convert_freq(freq)

        base, mult = _gfc(freq)
        new_data = self.asfreq(freq, how)

        new_data = period.periodarr_to_dt64arr(new_data._ndarray_values, base)
        return DatetimeIndex(new_data, freq='infer', name=self.name) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:30,代码来源:period.py

示例8: _range_from_fields

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def _range_from_fields(year=None, month=None, quarter=None, day=None,
                       hour=None, minute=None, second=None, freq=None):
    if hour is None:
        hour = 0
    if minute is None:
        minute = 0
    if second is None:
        second = 0
    if day is None:
        day = 1

    ordinals = []

    if quarter is not None:
        if freq is None:
            freq = 'Q'
            base = frequencies.FreqGroup.FR_QTR
        else:
            base, mult = _gfc(freq)
            if base != frequencies.FreqGroup.FR_QTR:
                raise AssertionError("base must equal FR_QTR")

        year, quarter = _make_field_arrays(year, quarter)
        for y, q in zip(year, quarter):
            y, m = _quarter_to_myear(y, q, freq)
            val = period.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
            ordinals.append(val)
    else:
        base, mult = _gfc(freq)
        arrays = _make_field_arrays(year, month, day, hour, minute, second)
        for y, mth, d, h, mn, s in zip(*arrays):
            ordinals.append(period.period_ordinal(
                y, mth, d, h, mn, s, 0, 0, base))

    return np.array(ordinals, dtype=np.int64), freq 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:37,代码来源:period.py

示例9: test_frequency_misc

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def test_frequency_misc(self):
        self.assertEquals(fmod.get_freq_group('T'),
                          fmod.FreqGroup.FR_MIN)

        code, stride = fmod.get_freq_code(offsets.Hour())
        self.assertEquals(code, fmod.FreqGroup.FR_HR)

        code, stride = fmod.get_freq_code((5, 'T'))
        self.assertEquals(code, fmod.FreqGroup.FR_MIN)
        self.assertEquals(stride, 5)

        offset = offsets.Hour()
        result = fmod.to_offset(offset)
        self.assertEquals(result, offset)

        result = fmod.to_offset((5, 'T'))
        expected = offsets.Minute(5)
        self.assertEquals(result, expected)

        self.assertRaises(ValueError, fmod.get_freq_code, (5, 'baz'))

        self.assertRaises(ValueError, fmod.to_offset, '100foo')

        self.assertRaises(ValueError, fmod.to_offset, ('', ''))

        result = fmod.get_standard_freq(offsets.Hour())
        self.assertEquals(result, 'H') 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:29,代码来源:test_timeseries.py

示例10: _field_accessor

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def _field_accessor(name, alias, docstring=None):
    def f(self):
        base, mult = _gfc(self.freq)
        result = get_period_field_arr(alias, self._values, base)
        return Index(result, name=self.name)
    f.__name__ = name
    f.__doc__ = docstring
    return property(f) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:10,代码来源:period.py

示例11: _period_index_cmp

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def _period_index_cmp(opname, nat_result=False):
    """
    Wrap comparison operations to convert datetime-like to datetime64
    """

    def wrapper(self, other):
        if isinstance(other, Period):
            func = getattr(self._values, opname)
            other_base, _ = _gfc(other.freq)
            if other.freq != self.freq:
                msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
                raise IncompatibleFrequency(msg)

            result = func(other.ordinal)
        elif isinstance(other, PeriodIndex):
            if other.freq != self.freq:
                msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
                raise IncompatibleFrequency(msg)

            result = getattr(self._values, opname)(other._values)

            mask = self._isnan | other._isnan
            if mask.any():
                result[mask] = nat_result

            return result
        elif other is tslib.NaT:
            result = np.empty(len(self._values), dtype=bool)
            result.fill(nat_result)
        else:
            other = Period(other, freq=self.freq)
            func = getattr(self._values, opname)
            result = func(other.ordinal)

        if self.hasnans:
            result[self._isnan] = nat_result

        return result
    return wrapper 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:41,代码来源:period.py

示例12: to_timestamp

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def to_timestamp(self, freq=None, how='start'):
        """
        Cast to DatetimeIndex

        Parameters
        ----------
        freq : string or DateOffset, default 'D' for week or longer, 'S'
               otherwise
            Target frequency
        how : {'s', 'e', 'start', 'end'}

        Returns
        -------
        DatetimeIndex
        """
        how = _validate_end_alias(how)

        if freq is None:
            base, mult = _gfc(self.freq)
            freq = frequencies.get_to_timestamp_base(base)
        else:
            freq = Period._maybe_convert_freq(freq)

        base, mult = _gfc(freq)
        new_data = self.asfreq(freq, how)

        new_data = period.periodarr_to_dt64arr(new_data._values, base)
        return DatetimeIndex(new_data, freq='infer', name=self.name) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:30,代码来源:period.py

示例13: test_frequency_misc

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def test_frequency_misc(self):
        assert (frequencies.get_freq_group('T') ==
                frequencies.FreqGroup.FR_MIN)

        code, stride = frequencies.get_freq_code(offsets.Hour())
        assert code == frequencies.FreqGroup.FR_HR

        code, stride = frequencies.get_freq_code((5, 'T'))
        assert code == frequencies.FreqGroup.FR_MIN
        assert stride == 5

        offset = offsets.Hour()
        result = frequencies.to_offset(offset)
        assert result == offset

        result = frequencies.to_offset((5, 'T'))
        expected = offsets.Minute(5)
        assert result == expected

        pytest.raises(ValueError, frequencies.get_freq_code, (5, 'baz'))

        pytest.raises(ValueError, frequencies.to_offset, '100foo')

        pytest.raises(ValueError, frequencies.to_offset, ('', ''))

        with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
            result = frequencies.get_standard_freq(offsets.Hour())
        assert result == 'H' 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:30,代码来源:test_timestamp.py

示例14: test_get_freq_code

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def test_get_freq_code(self):
        # frequency str
        assert (frequencies.get_freq_code('A') ==
                (frequencies.get_freq('A'), 1))
        assert (frequencies.get_freq_code('3D') ==
                (frequencies.get_freq('D'), 3))
        assert (frequencies.get_freq_code('-2M') ==
                (frequencies.get_freq('M'), -2))

        # tuple
        assert (frequencies.get_freq_code(('D', 1)) ==
                (frequencies.get_freq('D'), 1))
        assert (frequencies.get_freq_code(('A', 3)) ==
                (frequencies.get_freq('A'), 3))
        assert (frequencies.get_freq_code(('M', -2)) ==
                (frequencies.get_freq('M'), -2))

        # numeric tuple
        assert frequencies.get_freq_code((1000, 1)) == (1000, 1)

        # offsets
        assert (frequencies.get_freq_code(offsets.Day()) ==
                (frequencies.get_freq('D'), 1))
        assert (frequencies.get_freq_code(offsets.Day(3)) ==
                (frequencies.get_freq('D'), 3))
        assert (frequencies.get_freq_code(offsets.Day(-2)) ==
                (frequencies.get_freq('D'), -2))

        assert (frequencies.get_freq_code(offsets.MonthEnd()) ==
                (frequencies.get_freq('M'), 1))
        assert (frequencies.get_freq_code(offsets.MonthEnd(3)) ==
                (frequencies.get_freq('M'), 3))
        assert (frequencies.get_freq_code(offsets.MonthEnd(-2)) ==
                (frequencies.get_freq('M'), -2))

        assert (frequencies.get_freq_code(offsets.Week()) ==
                (frequencies.get_freq('W'), 1))
        assert (frequencies.get_freq_code(offsets.Week(3)) ==
                (frequencies.get_freq('W'), 3))
        assert (frequencies.get_freq_code(offsets.Week(-2)) ==
                (frequencies.get_freq('W'), -2))

        # Monday is weekday=0
        assert (frequencies.get_freq_code(offsets.Week(weekday=1)) ==
                (frequencies.get_freq('W-TUE'), 1))
        assert (frequencies.get_freq_code(offsets.Week(3, weekday=0)) ==
                (frequencies.get_freq('W-MON'), 3))
        assert (frequencies.get_freq_code(offsets.Week(-2, weekday=4)) ==
                (frequencies.get_freq('W-FRI'), -2)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:51,代码来源:test_frequencies.py

示例15: _get_ordinal_range

# 需要导入模块: from pandas.tseries import frequencies [as 别名]
# 或者: from pandas.tseries.frequencies import get_freq_code [as 别名]
def _get_ordinal_range(start, end, periods, freq, mult=1):
    if com._count_not_none(start, end, periods) != 2:
        raise ValueError('Of the three parameters: start, end, and periods, '
                         'exactly two must be specified')

    if freq is not None:
        _, mult = _gfc(freq)

    if start is not None:
        start = Period(start, freq)
    if end is not None:
        end = Period(end, freq)

    is_start_per = isinstance(start, Period)
    is_end_per = isinstance(end, Period)

    if is_start_per and is_end_per and start.freq != end.freq:
        raise ValueError('start and end must have same freq')
    if (start is tslib.NaT or end is tslib.NaT):
        raise ValueError('start and end must not be NaT')

    if freq is None:
        if is_start_per:
            freq = start.freq
        elif is_end_per:
            freq = end.freq
        else:  # pragma: no cover
            raise ValueError('Could not infer freq from start/end')

    if periods is not None:
        periods = periods * mult
        if start is None:
            data = np.arange(end.ordinal - periods + mult,
                             end.ordinal + 1, mult,
                             dtype=np.int64)
        else:
            data = np.arange(start.ordinal, start.ordinal + periods, mult,
                             dtype=np.int64)
    else:
        data = np.arange(start.ordinal, end.ordinal + 1, mult, dtype=np.int64)

    return data, freq 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:44,代码来源:period.py


注:本文中的pandas.tseries.frequencies.get_freq_code方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。