當前位置: 首頁>>代碼示例>>Python>>正文


Python pandas.offsets方法代碼示例

本文整理匯總了Python中pandas.offsets方法的典型用法代碼示例。如果您正苦於以下問題:Python pandas.offsets方法的具體用法?Python pandas.offsets怎麽用?Python pandas.offsets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas的用法示例。


在下文中一共展示了pandas.offsets方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_td64arr_add_offset_array

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_td64arr_add_offset_array(self, box):
        # GH#18849
        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'])
        other = np.array([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)])

        expected = TimedeltaIndex([tdi[n] + other[n] for n in range(len(tdi))],
                                  freq='infer')

        tdi = tm.box_expected(tdi, box)
        expected = tm.box_expected(expected, box)

        # The DataFrame operation is transposed and so operates as separate
        #  scalar operations, which do not issue a PerformanceWarning
        warn = PerformanceWarning if box is not pd.DataFrame else None
        with tm.assert_produces_warning(warn):
            res = tdi + other
        tm.assert_equal(res, expected)

        with tm.assert_produces_warning(warn):
            res2 = other + tdi
        tm.assert_equal(res2, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_timedelta64.py

示例2: test_td64arr_sub_offset_index

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_td64arr_sub_offset_index(self, names, box):
        # GH#18824, GH#19744
        if box is pd.DataFrame and names[1] == 'bar':
            pytest.skip("Name propagation for DataFrame does not behave like "
                        "it does for Index/Series")

        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'],
                             name=names[0])
        other = pd.Index([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)],
                         name=names[1])

        expected = TimedeltaIndex([tdi[n] - other[n] for n in range(len(tdi))],
                                  freq='infer', name=names[2])

        tdi = tm.box_expected(tdi, box)
        expected = tm.box_expected(expected, box)

        # The DataFrame operation is transposed and so operates as separate
        #  scalar operations, which do not issue a PerformanceWarning
        warn = PerformanceWarning if box is not pd.DataFrame else None
        with tm.assert_produces_warning(warn):
            res = tdi - other
        tm.assert_equal(res, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_timedelta64.py

示例3: test_td64arr_sub_offset_array

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_td64arr_sub_offset_array(self, box_with_array):
        # GH#18824
        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'])
        other = np.array([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)])

        expected = TimedeltaIndex([tdi[n] - other[n] for n in range(len(tdi))],
                                  freq='infer')

        tdi = tm.box_expected(tdi, box_with_array)
        expected = tm.box_expected(expected, box_with_array)

        # The DataFrame operation is transposed and so operates as separate
        #  scalar operations, which do not issue a PerformanceWarning
        warn = None if box_with_array is pd.DataFrame else PerformanceWarning
        with tm.assert_produces_warning(warn):
            res = tdi - other
        tm.assert_equal(res, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_timedelta64.py

示例4: test_td64arr_addsub_anchored_offset_arraylike

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_td64arr_addsub_anchored_offset_arraylike(self, obox,
                                                      box_with_array):
        # GH#18824
        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'])
        tdi = tm.box_expected(tdi, box_with_array)

        anchored = obox([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)])

        # addition/subtraction ops with anchored offsets should issue
        # a PerformanceWarning and _then_ raise a TypeError.
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                tdi + anchored
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                anchored + tdi
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                tdi - anchored
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                anchored - tdi 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_timedelta64.py

示例5: test_dt64arr_series_sub_tick_DateOffset

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_dt64arr_series_sub_tick_DateOffset(self, box_with_array):
        # GH#4532
        # operate with pd.offsets
        ser = Series([Timestamp('20130101 9:01'), Timestamp('20130101 9:02')])
        expected = Series([Timestamp('20130101 9:00:55'),
                           Timestamp('20130101 9:01:55')])

        ser = tm.box_expected(ser, box_with_array)
        expected = tm.box_expected(expected, box_with_array)

        result = ser - pd.offsets.Second(5)
        tm.assert_equal(result, expected)

        result2 = -pd.offsets.Second(5) + ser
        tm.assert_equal(result2, expected)

        with pytest.raises(TypeError):
            pd.offsets.Second(5) - ser 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_datetime64.py

示例6: test_dt64_series_add_mixed_tick_DateOffset

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_dt64_series_add_mixed_tick_DateOffset(self):
        # GH#4532
        # operate with pd.offsets
        s = Series([Timestamp('20130101 9:01'), Timestamp('20130101 9:02')])

        result = s + pd.offsets.Milli(5)
        result2 = pd.offsets.Milli(5) + s
        expected = Series([Timestamp('20130101 9:01:00.005'),
                           Timestamp('20130101 9:02:00.005')])
        tm.assert_series_equal(result, expected)
        tm.assert_series_equal(result2, expected)

        result = s + pd.offsets.Minute(5) + pd.offsets.Milli(5)
        expected = Series([Timestamp('20130101 9:06:00.005'),
                           Timestamp('20130101 9:07:00.005')])
        tm.assert_series_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_datetime64.py

示例7: test_dti_add_offset_index

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_dti_add_offset_index(self, tz_naive_fixture, names):
        # GH#18849, GH#19744
        tz = tz_naive_fixture
        dti = pd.date_range('2017-01-01', periods=2, tz=tz, name=names[0])
        other = pd.Index([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)],
                         name=names[1])

        with tm.assert_produces_warning(PerformanceWarning,
                                        clear=[pd.core.arrays.datetimelike]):
            res = dti + other
        expected = DatetimeIndex([dti[n] + other[n] for n in range(len(dti))],
                                 name=names[2], freq='infer')
        tm.assert_index_equal(res, expected)

        with tm.assert_produces_warning(PerformanceWarning,
                                        clear=[pd.core.arrays.datetimelike]):
            res2 = other + dti
        tm.assert_index_equal(res2, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_datetime64.py

示例8: test_dti_with_offset_series

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_dti_with_offset_series(self, tz, names):
        # GH#18849
        dti = pd.date_range('2017-01-01', periods=2, tz=tz, name=names[0])
        other = Series([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)],
                       name=names[1])

        expected_add = Series([dti[n] + other[n] for n in range(len(dti))],
                              name=names[2])

        with tm.assert_produces_warning(PerformanceWarning):
            res = dti + other
        tm.assert_series_equal(res, expected_add)

        with tm.assert_produces_warning(PerformanceWarning):
            res2 = other + dti
        tm.assert_series_equal(res2, expected_add)

        expected_sub = Series([dti[n] - other[n] for n in range(len(dti))],
                              name=names[2])

        with tm.assert_produces_warning(PerformanceWarning):
            res3 = dti - other
        tm.assert_series_equal(res3, expected_sub) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:test_arithmetic.py

示例9: test_dt64_with_offset_array

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_dt64_with_offset_array(klass, assert_func):
    # GH#10699
    # array of offsets
    box = Series if klass is Series else pd.Index
    with tm.assert_produces_warning(PerformanceWarning):
        s = klass([Timestamp('2000-1-1'), Timestamp('2000-2-1')])
        result = s + box([pd.offsets.DateOffset(years=1),
                          pd.offsets.MonthEnd()])
        exp = klass([Timestamp('2001-1-1'), Timestamp('2000-2-29')])
        assert_func(result, exp)

        # same offset
        result = s + box([pd.offsets.DateOffset(years=1),
                          pd.offsets.DateOffset(years=1)])
        exp = klass([Timestamp('2001-1-1'), Timestamp('2001-2-1')])
        assert_func(result, exp) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:test_arithmetic.py

示例10: test_dt64_series_add_mixed_tick_DateOffset

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_dt64_series_add_mixed_tick_DateOffset(self):
        # GH 4532
        # operate with pd.offsets
        s = Series([Timestamp('20130101 9:01'), Timestamp('20130101 9:02')])

        result = s + pd.offsets.Milli(5)
        result2 = pd.offsets.Milli(5) + s
        expected = Series([Timestamp('20130101 9:01:00.005'),
                           Timestamp('20130101 9:02:00.005')])
        assert_series_equal(result, expected)
        assert_series_equal(result2, expected)

        result = s + pd.offsets.Minute(5) + pd.offsets.Milli(5)
        expected = Series([Timestamp('20130101 9:06:00.005'),
                           Timestamp('20130101 9:07:00.005')])
        assert_series_equal(result, expected) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:test_operators.py

示例11: tick_classes

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def tick_classes(request):
    """
    Fixture for Tick based datetime offsets available for a time series.
    """
    return request.param

# ----------------------------------------------------------------
# Global setup for tests using Hypothesis


# Registering these strategies makes them globally available via st.from_type,
# which is use for offsets in tests/tseries/offsets/test_offsets_properties.py 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:conftest.py

示例12: test_timedelta

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_timedelta(self, freq):
        index = pd.date_range('1/1/2000', periods=50, freq=freq)

        shifted = index + timedelta(1)
        back = shifted + timedelta(-1)
        tm.assert_index_equal(index, back)

        if freq == 'D':
            expected = pd.tseries.offsets.Day(1)
            assert index.freq == expected
            assert shifted.freq == expected
            assert back.freq == expected
        else:  # freq == 'B'
            assert index.freq == pd.tseries.offsets.BusinessDay(1)
            assert shifted.freq is None
            assert back.freq == pd.tseries.offsets.BusinessDay(1)

        result = index - timedelta(1)
        expected = index + timedelta(-1)
        tm.assert_index_equal(result, expected)

        # GH#4134, buggy with timedeltas
        rng = pd.date_range('2013', '2014')
        s = Series(rng)
        result1 = rng - pd.offsets.Hour(1)
        result2 = DatetimeIndex(s - np.timedelta64(100000000))
        result3 = rng - np.timedelta64(100000000)
        result4 = DatetimeIndex(s - pd.offsets.Hour(1))
        tm.assert_index_equal(result1, result4)
        tm.assert_index_equal(result2, result3) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:32,代碼來源:test_timedelta64.py

示例13: test_td64arr_add_timedeltalike

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_td64arr_add_timedeltalike(self, two_hours, box):
        # only test adding/sub offsets as + is now numeric
        rng = timedelta_range('1 days', '10 days')
        expected = timedelta_range('1 days 02:00:00', '10 days 02:00:00',
                                   freq='D')
        rng = tm.box_expected(rng, box)
        expected = tm.box_expected(expected, box)

        result = rng + two_hours
        tm.assert_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_timedelta64.py

示例14: test_td64arr_sub_timedeltalike

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_td64arr_sub_timedeltalike(self, two_hours, box):
        # only test adding/sub offsets as - is now numeric
        rng = timedelta_range('1 days', '10 days')
        expected = timedelta_range('0 days 22:00:00', '9 days 22:00:00')

        rng = tm.box_expected(rng, box)
        expected = tm.box_expected(expected, box)

        result = rng - two_hours
        tm.assert_equal(result, expected)

    # ------------------------------------------------------------------
    # __add__/__sub__ with DateOffsets and arrays of DateOffsets

    # TODO: this was taken from tests.series.test_operators; de-duplicate 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:17,代碼來源:test_timedelta64.py

示例15: test_timedelta64_operations_with_DateOffset

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import offsets [as 別名]
def test_timedelta64_operations_with_DateOffset(self):
        # GH#10699
        td = Series([timedelta(minutes=5, seconds=3)] * 3)
        result = td + pd.offsets.Minute(1)
        expected = Series([timedelta(minutes=6, seconds=3)] * 3)
        tm.assert_series_equal(result, expected)

        result = td - pd.offsets.Minute(1)
        expected = Series([timedelta(minutes=4, seconds=3)] * 3)
        tm.assert_series_equal(result, expected)

        with tm.assert_produces_warning(PerformanceWarning):
            result = td + Series([pd.offsets.Minute(1), pd.offsets.Second(3),
                                  pd.offsets.Hour(2)])
        expected = Series([timedelta(minutes=6, seconds=3),
                           timedelta(minutes=5, seconds=6),
                           timedelta(hours=2, minutes=5, seconds=3)])
        tm.assert_series_equal(result, expected)

        result = td + pd.offsets.Minute(1) + pd.offsets.Second(12)
        expected = Series([timedelta(minutes=6, seconds=15)] * 3)
        tm.assert_series_equal(result, expected)

        # valid DateOffsets
        for do in ['Hour', 'Minute', 'Second', 'Day', 'Micro', 'Milli',
                   'Nano']:
            op = getattr(pd.offsets, do)
            td + op(5)
            op(5) + td
            td - op(5)
            op(5) - td 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:33,代碼來源:test_timedelta64.py


注:本文中的pandas.offsets方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。