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


Python errors.NullFrequencyError方法代码示例

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


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

示例1: test_tdi_addsub_integer_array_no_freq

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_tdi_addsub_integer_array_no_freq(self, box):
        # GH#19959
        tdi = TimedeltaIndex(['1 Day', 'NaT', '3 Hours'])
        other = box([14, -1, 16])
        with pytest.raises(NullFrequencyError):
            tdi + other
        with pytest.raises(NullFrequencyError):
            other + tdi
        with pytest.raises(NullFrequencyError):
            tdi - other
        with pytest.raises(NullFrequencyError):
            other - tdi

    # -------------------------------------------------------------
    # Binary operations TimedeltaIndex and timedelta-like
    # Note: add and sub are tested in tests.test_arithmetic, in-place
    #  tests are kept here because their behavior is Index-specific 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_arithmetic.py

示例2: test_shift2

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_shift2(self):
        ts = Series(np.random.randn(5),
                    index=date_range('1/1/2000', periods=5, freq='H'))

        result = ts.shift(1, freq='5T')
        exp_index = ts.index.shift(1, freq='5T')
        tm.assert_index_equal(result.index, exp_index)

        # GH #1063, multiple of same base
        result = ts.shift(1, freq='4H')
        exp_index = ts.index + offsets.Hour(4)
        tm.assert_index_equal(result.index, exp_index)

        idx = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-04'])
        msg = "Cannot shift with no freq"
        with pytest.raises(NullFrequencyError, match=msg):
            idx.shift(1) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_timeseries.py

示例3: test_td64arr_add_sub_numeric_scalar_invalid

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_td64arr_add_sub_numeric_scalar_invalid(self, box_with_array,
                                                    scalar):
        box = box_with_array

        tdser = pd.Series(['59 Days', '59 Days', 'NaT'], dtype='m8[ns]')
        tdser = tm.box_expected(tdser, box)
        err = TypeError
        if box in [pd.Index, tm.to_array] and not isinstance(scalar, float):
            err = NullFrequencyError

        with pytest.raises(err):
            tdser + scalar
        with pytest.raises(err):
            scalar + tdser
        with pytest.raises(err):
            tdser - scalar
        with pytest.raises(err):
            scalar - tdser 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_timedelta64.py

示例4: test_td64arr_add_sub_numeric_arr_invalid

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_td64arr_add_sub_numeric_arr_invalid(self, box, vec, dtype):
        tdser = pd.Series(['59 Days', '59 Days', 'NaT'], dtype='m8[ns]')
        tdser = tm.box_expected(tdser, box)
        err = TypeError
        if box is pd.Index and not dtype.startswith('float'):
            err = NullFrequencyError

        vector = vec.astype(dtype)
        with pytest.raises(err):
            tdser + vector
        with pytest.raises(err):
            vector + tdser
        with pytest.raises(err):
            tdser - vector
        with pytest.raises(err):
            vector - tdser

    # ------------------------------------------------------------------
    # Operations with timedelta-like others

    # TODO: this was taken from tests.series.test_ops; de-duplicate 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_timedelta64.py

示例5: test_shift_no_freq

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_shift_no_freq(self):
        # GH#19147
        tdi = TimedeltaIndex(['1 days 01:00:00', '2 days 01:00:00'], freq=None)
        with pytest.raises(NullFrequencyError):
            tdi.shift(2)

    # -------------------------------------------------------------
    # Binary operations TimedeltaIndex and integer 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_arithmetic.py

示例6: test_dti_shift_no_freq

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_dti_shift_no_freq(self):
        # GH#19147
        dti = pd.DatetimeIndex(['2011-01-01 10:00', '2011-01-01'], freq=None)
        with pytest.raises(NullFrequencyError):
            dti.shift(2) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_arithmetic.py

示例7: test_td64arr_add_intlike

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_td64arr_add_intlike(self, box_with_array):
        # GH#19123
        tdi = TimedeltaIndex(['59 days', '59 days', 'NaT'])
        ser = tm.box_expected(tdi, box_with_array)

        err = TypeError
        if box_with_array in [pd.Index, tm.to_array]:
            err = NullFrequencyError

        other = Series([20, 30, 40], dtype='uint8')

        # TODO: separate/parametrize
        with pytest.raises(err):
            ser + 1
        with pytest.raises(err):
            ser - 1

        with pytest.raises(err):
            ser + other
        with pytest.raises(err):
            ser - other

        with pytest.raises(err):
            ser + np.array(other)
        with pytest.raises(err):
            ser - np.array(other)

        with pytest.raises(err):
            ser + pd.Index(other)
        with pytest.raises(err):
            ser - pd.Index(other) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:test_timedelta64.py

示例8: test_dti_add_intarray_no_freq

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_dti_add_intarray_no_freq(self, int_holder):
        # GH#19959
        dti = pd.DatetimeIndex(['2016-01-01', 'NaT', '2017-04-05 06:07:08'])
        other = int_holder([9, 4, -1])
        with pytest.raises(NullFrequencyError):
            dti + other
        with pytest.raises(NullFrequencyError):
            other + dti
        with pytest.raises(NullFrequencyError):
            dti - other
        with pytest.raises(TypeError):
            other - dti

    # -------------------------------------------------------------
    # Binary operations DatetimeIndex and TimedeltaIndex/array 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_datetime64.py

示例9: dispatch_to_index_op

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def dispatch_to_index_op(op, left, right, index_class):
    """
    Wrap Series left in the given index_class to delegate the operation op
    to the index implementation.  DatetimeIndex and TimedeltaIndex perform
    type checking, timezone handling, overflow checks, etc.

    Parameters
    ----------
    op : binary operator (operator.add, operator.sub, ...)
    left : Series
    right : object
    index_class : DatetimeIndex or TimedeltaIndex

    Returns
    -------
    result : object, usually DatetimeIndex, TimedeltaIndex, or Series
    """
    left_idx = index_class(left)

    # avoid accidentally allowing integer add/sub.  For datetime64[tz] dtypes,
    # left_idx may inherit a freq from a cached DatetimeIndex.
    # See discussion in GH#19147.
    if getattr(left_idx, 'freq', None) is not None:
        left_idx = left_idx._shallow_copy(freq=None)
    try:
        result = op(left_idx, right)
    except NullFrequencyError:
        # DatetimeIndex and TimedeltaIndex with freq == None raise ValueError
        # on add/sub of integers (or int-like).  We re-raise as a TypeError.
        raise TypeError('incompatible type for a datetime/timedelta '
                        'operation [{name}]'.format(name=op.__name__))
    return result 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:34,代码来源:ops.py

示例10: test_shift_no_freq

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_shift_no_freq(self):
        # GH#19147
        tdi = TimedeltaIndex(['1 days 01:00:00', '2 days 01:00:00'], freq=None)
        with pytest.raises(NullFrequencyError):
            tdi.shift(2)

    # ------------------------------------------------------------- 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:test_arithmetic.py

示例11: test_shift2

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_shift2(self):
        ts = Series(np.random.randn(5),
                    index=date_range('1/1/2000', periods=5, freq='H'))

        result = ts.shift(1, freq='5T')
        exp_index = ts.index.shift(1, freq='5T')
        tm.assert_index_equal(result.index, exp_index)

        # GH #1063, multiple of same base
        result = ts.shift(1, freq='4H')
        exp_index = ts.index + offsets.Hour(4)
        tm.assert_index_equal(result.index, exp_index)

        idx = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-04'])
        pytest.raises(NullFrequencyError, idx.shift, 1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:17,代码来源:test_timeseries.py

示例12: shift

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def shift(self, n, freq=None):
        """
        Specialized shift which produces a DatetimeIndex

        Parameters
        ----------
        n : int
            Periods to shift by
        freq : DateOffset or timedelta-like, optional

        Returns
        -------
        shifted : DatetimeIndex
        """
        if freq is not None and freq != self.freq:
            if isinstance(freq, compat.string_types):
                freq = frequencies.to_offset(freq)
            offset = n * freq
            result = self + offset

            if hasattr(self, 'tz'):
                result._tz = self.tz

            return result

        if n == 0:
            # immutable so OK
            return self

        if self.freq is None:
            raise NullFrequencyError("Cannot shift with no freq")

        start = self[0] + n * self.freq
        end = self[-1] + n * self.freq
        attribs = self._get_attributes_dict()
        attribs['start'] = start
        attribs['end'] = end
        return type(self)(**attribs) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:40,代码来源:datetimelike.py

示例13: test_addition_ops

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_addition_ops(self):
        # with datetimes/timedelta and tdi/dti
        tdi = TimedeltaIndex(['1 days', pd.NaT, '2 days'], name='foo')
        dti = pd.date_range('20130101', periods=3, name='bar')
        td = Timedelta('1 days')
        dt = Timestamp('20130101')

        result = tdi + dt
        expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo')
        tm.assert_index_equal(result, expected)

        result = dt + tdi
        expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo')
        tm.assert_index_equal(result, expected)

        result = td + tdi
        expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo')
        tm.assert_index_equal(result, expected)

        result = tdi + td
        expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo')
        tm.assert_index_equal(result, expected)

        # unequal length
        pytest.raises(ValueError, lambda: tdi + dti[0:1])
        pytest.raises(ValueError, lambda: tdi[0:1] + dti)

        # random indexes
        with pytest.raises(NullFrequencyError):
            tdi + pd.Int64Index([1, 2, 3])

        # this is a union!
        # pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi)

        result = tdi + dti  # name will be reset
        expected = DatetimeIndex(['20130102', pd.NaT, '20130105'])
        tm.assert_index_equal(result, expected)

        result = dti + tdi  # name will be reset
        expected = DatetimeIndex(['20130102', pd.NaT, '20130105'])
        tm.assert_index_equal(result, expected)

        result = dt + td
        expected = Timestamp('20130102')
        assert result == expected

        result = td + dt
        expected = Timestamp('20130102')
        assert result == expected

    # TODO: Needs more informative name, probably split up into
    # more targeted tests 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:54,代码来源:test_timedelta64.py

示例14: test_addition_ops

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import NullFrequencyError [as 别名]
def test_addition_ops(self):
        # with datetimes/timedelta and tdi/dti
        tdi = TimedeltaIndex(['1 days', pd.NaT, '2 days'], name='foo')
        dti = date_range('20130101', periods=3, name='bar')
        td = Timedelta('1 days')
        dt = Timestamp('20130101')

        result = tdi + dt
        expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo')
        tm.assert_index_equal(result, expected)

        result = dt + tdi
        expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo')
        tm.assert_index_equal(result, expected)

        result = td + tdi
        expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo')
        tm.assert_index_equal(result, expected)

        result = tdi + td
        expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo')
        tm.assert_index_equal(result, expected)

        # unequal length
        pytest.raises(ValueError, lambda: tdi + dti[0:1])
        pytest.raises(ValueError, lambda: tdi[0:1] + dti)

        # random indexes
        pytest.raises(NullFrequencyError, lambda: tdi + Int64Index([1, 2, 3]))

        # this is a union!
        # pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi)

        result = tdi + dti  # name will be reset
        expected = DatetimeIndex(['20130102', pd.NaT, '20130105'])
        tm.assert_index_equal(result, expected)

        result = dti + tdi  # name will be reset
        expected = DatetimeIndex(['20130102', pd.NaT, '20130105'])
        tm.assert_index_equal(result, expected)

        result = dt + td
        expected = Timestamp('20130102')
        assert result == expected

        result = td + dt
        expected = Timestamp('20130102')
        assert result == expected 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:50,代码来源:test_arithmetic.py


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