コード例 #1
0
def test_shift_month():
    dt = datetime(2017, 11, 15)

    assert liboffsets.shift_month(dt, 0, day_opt=None) == dt
    assert liboffsets.shift_month(dt, 0, day_opt=15) == dt

    assert liboffsets.shift_month(dt, 1,
                                  day_opt='start') == datetime(2017, 12, 1)

    assert liboffsets.shift_month(dt, -145,
                                  day_opt='end') == datetime(2005, 10, 31)

    with pytest.raises(ValueError):
        liboffsets.shift_month(dt, 3, day_opt='this should raise')
コード例 #2
0
ファイル: test_liboffsets.py プロジェクト: cpcloud/pandas
def test_shift_month():
    dt = datetime(2017, 11, 30)
    assert liboffsets.shift_month(dt, 0, 'business_end') == dt
    assert liboffsets.shift_month(dt, 0,
                                  'business_start') == datetime(2017, 11, 1)

    ts = Timestamp('1929-05-05')
    assert liboffsets.shift_month(ts, 1, 'start') == Timestamp('1929-06-01')
    assert liboffsets.shift_month(ts, -3, 'end') == Timestamp('1929-02-28')

    assert liboffsets.shift_month(ts, 25, None) == Timestamp('1931-06-5')

    # Try to shift to April 31, then shift back to Apr 30 to get a real date
    assert liboffsets.shift_month(ts, -1, 31) == Timestamp('1929-04-30')

    dt = datetime(2017, 11, 15)

    assert liboffsets.shift_month(dt, 0, day_opt=None) == dt
    assert liboffsets.shift_month(dt, 0, day_opt=15) == dt

    assert liboffsets.shift_month(dt, 1,
                                  day_opt='start') == datetime(2017, 12, 1)

    assert liboffsets.shift_month(dt, -145,
                                  day_opt='end') == datetime(2005, 10, 31)

    with pytest.raises(ValueError):
        liboffsets.shift_month(dt, 3, day_opt='this should raise')
コード例 #3
0
def test_shift_month():
    dt = datetime(2017, 11, 30)
    assert liboffsets.shift_month(dt, 0, 'business_end') == dt
    assert liboffsets.shift_month(dt, 0,
                                  'business_start') == datetime(2017, 11, 1)

    ts = Timestamp('1929-05-05')
    assert liboffsets.shift_month(ts, 1, 'start') == Timestamp('1929-06-01')
    assert liboffsets.shift_month(ts, -3, 'end') == Timestamp('1929-02-28')

    assert liboffsets.shift_month(ts, 25, None) == Timestamp('1931-06-5')

    # Try to shift to April 31, then shift back to Apr 30 to get a real date
    assert liboffsets.shift_month(ts, -1, 31) == Timestamp('1929-04-30')

    dt = datetime(2017, 11, 15)

    assert liboffsets.shift_month(dt, 0, day_opt=None) == dt
    assert liboffsets.shift_month(dt, 0, day_opt=15) == dt

    assert liboffsets.shift_month(dt, 1,
                                  day_opt='start') == datetime(2017, 12, 1)

    assert liboffsets.shift_month(dt, -145,
                                  day_opt='end') == datetime(2005, 10, 31)

    with pytest.raises(ValueError):
        liboffsets.shift_month(dt, 3, day_opt='this should raise')
コード例 #4
0
def test_shift_month_error():
    dt = datetime(2017, 11, 15)
    day_opt = "this should raise"

    with pytest.raises(ValueError, match=day_opt):
        liboffsets.shift_month(dt, 3, day_opt=day_opt)
コード例 #5
0
def test_shift_month_ts(months, day_opt, expected):
    ts = Timestamp("1929-05-05")
    assert liboffsets.shift_month(ts, months, day_opt=day_opt) == expected
コード例 #6
0
def test_shift_month_dt(months, day_opt, expected):
    dt = datetime(2017, 11, 30)
    assert liboffsets.shift_month(dt, months, day_opt=day_opt) == expected