Skip to content

Commit f724066

Browse files
jbrockmendeljreback
authored andcommitted
parametrize more tests, move to test_liboffstes (#18346)
1 parent 0522dcc commit f724066

File tree

2 files changed

+352
-356
lines changed

2 files changed

+352
-356
lines changed

pandas/tests/tseries/offsets/test_liboffsets.py

+42-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,51 @@
66

77
import pytest
88

9-
import pandas as pd
9+
from pandas._libs import tslib
10+
from pandas import Timestamp
1011

1112
import pandas._libs.tslibs.offsets as liboffsets
1213

1314

15+
def test_get_lastbday():
16+
dt = datetime(2017, 11, 30)
17+
assert dt.weekday() == 3 # i.e. this is a business day
18+
wkday, days_in_month = tslib.monthrange(dt.year, dt.month)
19+
assert liboffsets.get_lastbday(wkday, days_in_month) == 30
20+
21+
dt = datetime(1993, 10, 31)
22+
assert dt.weekday() == 6 # i.e. this is not a business day
23+
wkday, days_in_month = tslib.monthrange(dt.year, dt.month)
24+
assert liboffsets.get_lastbday(wkday, days_in_month) == 29
25+
26+
27+
def test_get_firstbday():
28+
dt = datetime(2017, 4, 1)
29+
assert dt.weekday() == 5 # i.e. not a weekday
30+
wkday, days_in_month = tslib.monthrange(dt.year, dt.month)
31+
assert liboffsets.get_firstbday(wkday, days_in_month) == 3
32+
33+
dt = datetime(1993, 10, 1)
34+
assert dt.weekday() == 4 # i.e. a business day
35+
wkday, days_in_month = tslib.monthrange(dt.year, dt.month)
36+
assert liboffsets.get_firstbday(wkday, days_in_month) == 1
37+
38+
1439
def test_shift_month():
40+
dt = datetime(2017, 11, 30)
41+
assert liboffsets.shift_month(dt, 0, 'business_end') == dt
42+
assert liboffsets.shift_month(dt, 0,
43+
'business_start') == datetime(2017, 11, 1)
44+
45+
ts = Timestamp('1929-05-05')
46+
assert liboffsets.shift_month(ts, 1, 'start') == Timestamp('1929-06-01')
47+
assert liboffsets.shift_month(ts, -3, 'end') == Timestamp('1929-02-28')
48+
49+
assert liboffsets.shift_month(ts, 25, None) == Timestamp('1931-06-5')
50+
51+
# Try to shift to April 31, then shift back to Apr 30 to get a real date
52+
assert liboffsets.shift_month(ts, -1, 31) == Timestamp('1929-04-30')
53+
1554
dt = datetime(2017, 11, 15)
1655

1756
assert liboffsets.shift_month(dt, 0, day_opt=None) == dt
@@ -45,7 +84,7 @@ def test_roll_yearday():
4584
assert liboffsets.roll_yearday(other, -7, month, day_opt) == -7
4685
assert liboffsets.roll_yearday(other, 0, month, day_opt) == 0
4786

48-
other = pd.Timestamp('2014-03-15', tz='US/Eastern') # after March 1
87+
other = Timestamp('2014-03-15', tz='US/Eastern') # after March 1
4988
assert liboffsets.roll_yearday(other, 2, month, day_opt) == 2
5089
assert liboffsets.roll_yearday(other, -7, month, day_opt) == -6
5190
assert liboffsets.roll_yearday(other, 0, month, day_opt) == 1
@@ -57,7 +96,7 @@ def test_roll_yearday():
5796
assert liboffsets.roll_yearday(other, -7, month, day_opt) == -7
5897
assert liboffsets.roll_yearday(other, 0, month, day_opt) == 0
5998

60-
other = pd.Timestamp(2072, 8, 24, 6, 17, 18) # after June 30
99+
other = Timestamp(2072, 8, 24, 6, 17, 18) # after June 30
61100
assert liboffsets.roll_yearday(other, 5, month, day_opt) == 5
62101
assert liboffsets.roll_yearday(other, -7, month, day_opt) == -6
63102
assert liboffsets.roll_yearday(other, 0, month, day_opt) == 1

0 commit comments

Comments
 (0)