コード例 #1
0
class TestBYearBegin(Base):
    _offset = BYearBegin

    def test_misspecified(self):
        msg = "Month must go from 1 to 12"
        with pytest.raises(ValueError, match=msg):
            BYearBegin(month=13)
        with pytest.raises(ValueError, match=msg):
            BYearEnd(month=13)

    offset_cases = []
    offset_cases.append(
        (
            BYearBegin(),
            {
                datetime(2008, 1, 1): datetime(2009, 1, 1),
                datetime(2008, 6, 30): datetime(2009, 1, 1),
                datetime(2008, 12, 31): datetime(2009, 1, 1),
                datetime(2011, 1, 1): datetime(2011, 1, 3),
                datetime(2011, 1, 3): datetime(2012, 1, 2),
                datetime(2005, 12, 30): datetime(2006, 1, 2),
                datetime(2005, 12, 31): datetime(2006, 1, 2),
            },
        )
    )

    offset_cases.append(
        (
            BYearBegin(0),
            {
                datetime(2008, 1, 1): datetime(2008, 1, 1),
                datetime(2008, 6, 30): datetime(2009, 1, 1),
                datetime(2008, 12, 31): datetime(2009, 1, 1),
                datetime(2005, 12, 30): datetime(2006, 1, 2),
                datetime(2005, 12, 31): datetime(2006, 1, 2),
            },
        )
    )

    offset_cases.append(
        (
            BYearBegin(-1),
            {
                datetime(2007, 1, 1): datetime(2006, 1, 2),
                datetime(2009, 1, 4): datetime(2009, 1, 1),
                datetime(2009, 1, 1): datetime(2008, 1, 1),
                datetime(2008, 6, 30): datetime(2008, 1, 1),
                datetime(2008, 12, 31): datetime(2008, 1, 1),
                datetime(2006, 12, 29): datetime(2006, 1, 2),
                datetime(2006, 12, 30): datetime(2006, 1, 2),
                datetime(2006, 1, 1): datetime(2005, 1, 3),
            },
        )
    )

    offset_cases.append(
        (
            BYearBegin(-2),
            {
                datetime(2007, 1, 1): datetime(2005, 1, 3),
                datetime(2007, 6, 30): datetime(2006, 1, 2),
                datetime(2008, 12, 31): datetime(2007, 1, 1),
            },
        )
    )

    @pytest.mark.parametrize("case", offset_cases)
    def test_offset(self, case):
        offset, cases = case
        for base, expected in cases.items():
            assert_offset_equal(offset, base, expected)
コード例 #2
0
 def test_misspecified(self):
     msg = "Month must go from 1 to 12"
     with pytest.raises(ValueError, match=msg):
         BYearBegin(month=13)
     with pytest.raises(ValueError, match=msg):
         BYearEnd(month=13)
コード例 #3
0
    # Annual - Business
    'BA-JAN': BYearEnd(month=1),
    'BA-FEB': BYearEnd(month=2),
    'BA-MAR': BYearEnd(month=3),
    'BA-APR': BYearEnd(month=4),
    'BA-MAY': BYearEnd(month=5),
    'BA-JUN': BYearEnd(month=6),
    'BA-JUL': BYearEnd(month=7),
    'BA-AUG': BYearEnd(month=8),
    'BA-SEP': BYearEnd(month=9),
    'BA-OCT': BYearEnd(month=10),
    'BA-NOV': BYearEnd(month=11),
    'BA-DEC': BYearEnd(month=12),

    # Annual - Business (Start)
    'BAS-JAN': BYearBegin(month=1),
    'BAS-FEB': BYearBegin(month=2),
    'BAS-MAR': BYearBegin(month=3),
    'BAS-APR': BYearBegin(month=4),
    'BAS-MAY': BYearBegin(month=5),
    'BAS-JUN': BYearBegin(month=6),
    'BAS-JUL': BYearBegin(month=7),
    'BAS-AUG': BYearBegin(month=8),
    'BAS-SEP': BYearBegin(month=9),
    'BAS-OCT': BYearBegin(month=10),
    'BAS-NOV': BYearBegin(month=11),
    'BAS-DEC': BYearBegin(month=12),

    # Quarterly - Calendar
    # 'Q'     : QuarterEnd(startingMonth=3),
    'Q-JAN': QuarterEnd(startingMonth=1),