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


Python offsets.SemiMonthBegin方法代碼示例

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


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

示例1: test_to_offset_invalid

# 需要導入模塊: from pandas.tseries import offsets [as 別名]
# 或者: from pandas.tseries.offsets import SemiMonthBegin [as 別名]
def test_to_offset_invalid(self):
        # GH 13930
        with pytest.raises(ValueError, match='Invalid frequency: U1'):
            frequencies.to_offset('U1')
        with pytest.raises(ValueError, match='Invalid frequency: -U'):
            frequencies.to_offset('-U')
        with pytest.raises(ValueError, match='Invalid frequency: 3U1'):
            frequencies.to_offset('3U1')
        with pytest.raises(ValueError, match='Invalid frequency: -2-3U'):
            frequencies.to_offset('-2-3U')
        with pytest.raises(ValueError, match='Invalid frequency: -2D:3H'):
            frequencies.to_offset('-2D:3H')
        with pytest.raises(ValueError, match='Invalid frequency: 1.5.0S'):
            frequencies.to_offset('1.5.0S')

        # split offsets with spaces are valid
        assert frequencies.to_offset('2D 3H') == offsets.Hour(51)
        assert frequencies.to_offset('2 D3 H') == offsets.Hour(51)
        assert frequencies.to_offset('2 D 3 H') == offsets.Hour(51)
        assert frequencies.to_offset('  2 D 3 H  ') == offsets.Hour(51)
        assert frequencies.to_offset('   H    ') == offsets.Hour()
        assert frequencies.to_offset(' 3  H    ') == offsets.Hour(3)

        # special cases
        assert frequencies.to_offset('2SMS-15') == offsets.SemiMonthBegin(2)
        with pytest.raises(ValueError, match='Invalid frequency: 2SMS-15-15'):
            frequencies.to_offset('2SMS-15-15')
        with pytest.raises(ValueError, match='Invalid frequency: 2SMS-15D'):
            frequencies.to_offset('2SMS-15D') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:31,代碼來源:test_frequencies.py

示例2: test_to_offset_invalid

# 需要導入模塊: from pandas.tseries import offsets [as 別名]
# 或者: from pandas.tseries.offsets import SemiMonthBegin [as 別名]
def test_to_offset_invalid(self):
        # GH 13930
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: U1'):
            frequencies.to_offset('U1')
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: -U'):
            frequencies.to_offset('-U')
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: 3U1'):
            frequencies.to_offset('3U1')
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: -2-3U'):
            frequencies.to_offset('-2-3U')
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: -2D:3H'):
            frequencies.to_offset('-2D:3H')
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: 1.5.0S'):
            frequencies.to_offset('1.5.0S')

        # split offsets with spaces are valid
        assert frequencies.to_offset('2D 3H') == offsets.Hour(51)
        assert frequencies.to_offset('2 D3 H') == offsets.Hour(51)
        assert frequencies.to_offset('2 D 3 H') == offsets.Hour(51)
        assert frequencies.to_offset('  2 D 3 H  ') == offsets.Hour(51)
        assert frequencies.to_offset('   H    ') == offsets.Hour()
        assert frequencies.to_offset(' 3  H    ') == offsets.Hour(3)

        # special cases
        assert frequencies.to_offset('2SMS-15') == offsets.SemiMonthBegin(2)
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: 2SMS-15-15'):
            frequencies.to_offset('2SMS-15-15')
        with tm.assert_raises_regex(ValueError,
                                    'Invalid frequency: 2SMS-15D'):
            frequencies.to_offset('2SMS-15D') 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:39,代碼來源:test_frequencies.py

示例3: test_anchored_shortcuts

# 需要導入模塊: from pandas.tseries import offsets [as 別名]
# 或者: from pandas.tseries.offsets import SemiMonthBegin [as 別名]
def test_anchored_shortcuts(self):
        result = frequencies.to_offset('W')
        expected = frequencies.to_offset('W-SUN')
        assert (result == expected)

        result1 = frequencies.to_offset('Q')
        result2 = frequencies.to_offset('Q-DEC')
        expected = offsets.QuarterEnd(startingMonth=12)
        assert (result1 == expected)
        assert (result2 == expected)

        result1 = frequencies.to_offset('Q-MAY')
        expected = offsets.QuarterEnd(startingMonth=5)
        assert (result1 == expected)

        result1 = frequencies.to_offset('SM')
        result2 = frequencies.to_offset('SM-15')
        expected = offsets.SemiMonthEnd(day_of_month=15)
        assert (result1 == expected)
        assert (result2 == expected)

        result = frequencies.to_offset('SM-1')
        expected = offsets.SemiMonthEnd(day_of_month=1)
        assert (result == expected)

        result = frequencies.to_offset('SM-27')
        expected = offsets.SemiMonthEnd(day_of_month=27)
        assert (result == expected)

        result = frequencies.to_offset('SMS-2')
        expected = offsets.SemiMonthBegin(day_of_month=2)
        assert (result == expected)

        result = frequencies.to_offset('SMS-27')
        expected = offsets.SemiMonthBegin(day_of_month=27)
        assert (result == expected)

        # ensure invalid cases fail as expected
        invalid_anchors = ['SM-0', 'SM-28', 'SM-29',
                           'SM-FOO', 'BSM', 'SM--1',
                           'SMS-1', 'SMS-28', 'SMS-30',
                           'SMS-BAR', 'SMS-BYR' 'BSMS',
                           'SMS--2']
        for invalid_anchor in invalid_anchors:
            with pytest.raises(ValueError, match='Invalid frequency: '):
                frequencies.to_offset(invalid_anchor) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:48,代碼來源:test_frequencies.py

示例4: test_anchored_shortcuts

# 需要導入模塊: from pandas.tseries import offsets [as 別名]
# 或者: from pandas.tseries.offsets import SemiMonthBegin [as 別名]
def test_anchored_shortcuts(self):
        result = frequencies.to_offset('W')
        expected = frequencies.to_offset('W-SUN')
        assert (result == expected)

        result1 = frequencies.to_offset('Q')
        result2 = frequencies.to_offset('Q-DEC')
        expected = offsets.QuarterEnd(startingMonth=12)
        assert (result1 == expected)
        assert (result2 == expected)

        result1 = frequencies.to_offset('Q-MAY')
        expected = offsets.QuarterEnd(startingMonth=5)
        assert (result1 == expected)

        result1 = frequencies.to_offset('SM')
        result2 = frequencies.to_offset('SM-15')
        expected = offsets.SemiMonthEnd(day_of_month=15)
        assert (result1 == expected)
        assert (result2 == expected)

        result = frequencies.to_offset('SM-1')
        expected = offsets.SemiMonthEnd(day_of_month=1)
        assert (result == expected)

        result = frequencies.to_offset('SM-27')
        expected = offsets.SemiMonthEnd(day_of_month=27)
        assert (result == expected)

        result = frequencies.to_offset('SMS-2')
        expected = offsets.SemiMonthBegin(day_of_month=2)
        assert (result == expected)

        result = frequencies.to_offset('SMS-27')
        expected = offsets.SemiMonthBegin(day_of_month=27)
        assert (result == expected)

        # ensure invalid cases fail as expected
        invalid_anchors = ['SM-0', 'SM-28', 'SM-29',
                           'SM-FOO', 'BSM', 'SM--1',
                           'SMS-1', 'SMS-28', 'SMS-30',
                           'SMS-BAR', 'SMS-BYR' 'BSMS',
                           'SMS--2']
        for invalid_anchor in invalid_anchors:
            with tm.assert_raises_regex(ValueError,
                                        'Invalid frequency: '):
                frequencies.to_offset(invalid_anchor) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:49,代碼來源:test_frequencies.py


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