Python pandas.tseries.offsets.SemiMonthBegin() Examples

The following are 12 code examples of pandas.tseries.offsets.SemiMonthBegin(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.tseries.offsets , or try the search function .
Example #1
Source File: test_frequencies.py    From recruit with Apache License 2.0 5 votes vote down vote up
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') 
Example #2
Source File: test_frequencies.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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') 
Example #3
Source File: test_frequencies.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
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') 
Example #4
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
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') 
Example #5
Source File: test_frequencies.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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') 
Example #6
Source File: test_frequencies.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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') 
Example #7
Source File: test_frequencies.py    From recruit with Apache License 2.0 4 votes vote down vote up
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) 
Example #8
Source File: test_frequencies.py    From vnpy_crypto with MIT License 4 votes vote down vote up
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) 
Example #9
Source File: test_frequencies.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 4 votes vote down vote up
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) 
Example #10
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 4 votes vote down vote up
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) 
Example #11
Source File: test_frequencies.py    From coffeegrindsize with MIT License 4 votes vote down vote up
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) 
Example #12
Source File: test_frequencies.py    From twitter-stock-recommendation with MIT License 4 votes vote down vote up
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)