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


Python offsets.YearBegin方法代碼示例

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


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

示例1: test_sub_offset

# 需要導入模塊: from pandas import offsets [as 別名]
# 或者: from pandas.offsets import YearBegin [as 別名]
def test_sub_offset(self):
        # freq is DateOffset
        for freq in ['A', '2A', '3A']:
            p = Period('2011', freq=freq)
            assert p - offsets.YearEnd(2) == Period('2009', freq=freq)

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(365, 'D'),
                      timedelta(365)]:
                with pytest.raises(period.IncompatibleFrequency):
                    p - o

        for freq in ['M', '2M', '3M']:
            p = Period('2011-03', freq=freq)
            assert p - offsets.MonthEnd(2) == Period('2011-01', freq=freq)
            assert p - offsets.MonthEnd(12) == Period('2010-03', freq=freq)

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(365, 'D'),
                      timedelta(365)]:
                with pytest.raises(period.IncompatibleFrequency):
                    p - o

        # freq is Tick
        for freq in ['D', '2D', '3D']:
            p = Period('2011-04-01', freq=freq)
            assert p - offsets.Day(5) == Period('2011-03-27', freq=freq)
            assert p - offsets.Hour(24) == Period('2011-03-31', freq=freq)
            assert p - np.timedelta64(2, 'D') == Period(
                '2011-03-30', freq=freq)
            assert p - np.timedelta64(3600 * 24, 's') == Period(
                '2011-03-31', freq=freq)
            assert p - timedelta(-2) == Period('2011-04-03', freq=freq)
            assert p - timedelta(hours=48) == Period('2011-03-30', freq=freq)

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(4, 'h'),
                      timedelta(hours=23)]:
                with pytest.raises(period.IncompatibleFrequency):
                    p - o

        for freq in ['H', '2H', '3H']:
            p = Period('2011-04-01 09:00', freq=freq)
            assert p - offsets.Day(2) == Period('2011-03-30 09:00', freq=freq)
            assert p - offsets.Hour(3) == Period('2011-04-01 06:00', freq=freq)
            assert p - np.timedelta64(3, 'h') == Period(
                '2011-04-01 06:00', freq=freq)
            assert p - np.timedelta64(3600, 's') == Period(
                '2011-04-01 08:00', freq=freq)
            assert p - timedelta(minutes=120) == Period(
                '2011-04-01 07:00', freq=freq)
            assert p - timedelta(days=4, minutes=180) == Period(
                '2011-03-28 06:00', freq=freq)

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(3200, 's'),
                      timedelta(hours=23, minutes=30)]:
                with pytest.raises(period.IncompatibleFrequency):
                    p - o 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:61,代碼來源:test_period.py

示例2: test_sub_offset_nat

# 需要導入模塊: from pandas import offsets [as 別名]
# 或者: from pandas.offsets import YearBegin [as 別名]
def test_sub_offset_nat(self):
        # freq is DateOffset
        for freq in ['A', '2A', '3A']:
            p = Period('NaT', freq=freq)
            for o in [offsets.YearEnd(2)]:
                assert p - o is NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(365, 'D'),
                      timedelta(365)]:
                assert p - o is NaT

        for freq in ['M', '2M', '3M']:
            p = Period('NaT', freq=freq)
            for o in [offsets.MonthEnd(2), offsets.MonthEnd(12)]:
                assert p - o is NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(365, 'D'),
                      timedelta(365)]:
                assert p - o is NaT

        # freq is Tick
        for freq in ['D', '2D', '3D']:
            p = Period('NaT', freq=freq)
            for o in [offsets.Day(5), offsets.Hour(24), np.timedelta64(2, 'D'),
                      np.timedelta64(3600 * 24, 's'), timedelta(-2),
                      timedelta(hours=48)]:
                assert p - o is NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(4, 'h'),
                      timedelta(hours=23)]:
                assert p - o is NaT

        for freq in ['H', '2H', '3H']:
            p = Period('NaT', freq=freq)
            for o in [offsets.Day(2), offsets.Hour(3), np.timedelta64(3, 'h'),
                      np.timedelta64(3600, 's'), timedelta(minutes=120),
                      timedelta(days=4, minutes=180)]:
                assert p - o is NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(3200, 's'),
                      timedelta(hours=23, minutes=30)]:
                assert p - o is NaT 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:48,代碼來源:test_period.py

示例3: test_sub_offset_nat

# 需要導入模塊: from pandas import offsets [as 別名]
# 或者: from pandas.offsets import YearBegin [as 別名]
def test_sub_offset_nat(self):
        # freq is DateOffset
        for freq in ['A', '2A', '3A']:
            p = Period('NaT', freq=freq)
            for o in [offsets.YearEnd(2)]:
                assert p - o is tslib.NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(365, 'D'),
                      timedelta(365)]:
                assert p - o is tslib.NaT

        for freq in ['M', '2M', '3M']:
            p = Period('NaT', freq=freq)
            for o in [offsets.MonthEnd(2), offsets.MonthEnd(12)]:
                assert p - o is tslib.NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(365, 'D'),
                      timedelta(365)]:
                assert p - o is tslib.NaT

        # freq is Tick
        for freq in ['D', '2D', '3D']:
            p = Period('NaT', freq=freq)
            for o in [offsets.Day(5), offsets.Hour(24), np.timedelta64(2, 'D'),
                      np.timedelta64(3600 * 24, 's'), timedelta(-2),
                      timedelta(hours=48)]:
                assert p - o is tslib.NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(4, 'h'),
                      timedelta(hours=23)]:
                assert p - o is tslib.NaT

        for freq in ['H', '2H', '3H']:
            p = Period('NaT', freq=freq)
            for o in [offsets.Day(2), offsets.Hour(3), np.timedelta64(3, 'h'),
                      np.timedelta64(3600, 's'), timedelta(minutes=120),
                      timedelta(days=4, minutes=180)]:
                assert p - o is tslib.NaT

            for o in [offsets.YearBegin(2), offsets.MonthBegin(1),
                      offsets.Minute(), np.timedelta64(3200, 's'),
                      timedelta(hours=23, minutes=30)]:
                assert p - o is tslib.NaT 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:48,代碼來源:test_period.py


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