26
26
)
27
27
28
28
29
- def _check_holiday_results (holiday , start , end , expected ):
30
- """
31
- Check that the dates for a given holiday match in date and timezone.
32
-
33
- Parameters
34
- ----------
35
- holiday : Holiday
36
- The holiday to check.
37
- start : datetime-like
38
- The start date of range in which to collect dates for a given holiday.
39
- end : datetime-like
40
- The end date of range in which to collect dates for a given holiday.
41
- expected : list
42
- The list of dates we expect to get.
43
- """
44
- assert list (holiday .dates (start , end )) == expected
45
-
46
- # Verify that timezone info is preserved.
47
- assert list (
48
- holiday .dates (utc .localize (Timestamp (start )), utc .localize (Timestamp (end )))
49
- ) == [utc .localize (dt ) for dt in expected ]
50
-
51
-
52
29
@pytest .mark .parametrize (
53
30
"holiday,start_date,end_date,expected" ,
54
31
[
@@ -141,46 +118,61 @@ def _check_holiday_results(holiday, start, end, expected):
141
118
],
142
119
)
143
120
def test_holiday_dates (holiday , start_date , end_date , expected ):
144
- _check_holiday_results (holiday , start_date , end_date , expected )
121
+ assert list (holiday .dates (start_date , end_date )) == expected
122
+
123
+ # Verify that timezone info is preserved.
124
+ assert list (
125
+ holiday .dates (
126
+ utc .localize (Timestamp (start_date )), utc .localize (Timestamp (end_date ))
127
+ )
128
+ ) == [utc .localize (dt ) for dt in expected ]
145
129
146
130
147
131
@pytest .mark .parametrize (
148
132
"holiday,start,expected" ,
149
133
[
150
134
(USMemorialDay , datetime (2015 , 7 , 1 ), []),
151
- (USMemorialDay , "2015-05-25" , "2015-05-25" ),
135
+ (USMemorialDay , "2015-05-25" , [ Timestamp ( "2015-05-25" )] ),
152
136
(USLaborDay , datetime (2015 , 7 , 1 ), []),
153
- (USLaborDay , "2015-09-07" , "2015-09-07" ),
137
+ (USLaborDay , "2015-09-07" , [ Timestamp ( "2015-09-07" )] ),
154
138
(USColumbusDay , datetime (2015 , 7 , 1 ), []),
155
- (USColumbusDay , "2015-10-12" , "2015-10-12" ),
139
+ (USColumbusDay , "2015-10-12" , [ Timestamp ( "2015-10-12" )] ),
156
140
(USThanksgivingDay , datetime (2015 , 7 , 1 ), []),
157
- (USThanksgivingDay , "2015-11-26" , "2015-11-26" ),
141
+ (USThanksgivingDay , "2015-11-26" , [ Timestamp ( "2015-11-26" )] ),
158
142
(USMartinLutherKingJr , datetime (2015 , 7 , 1 ), []),
159
- (USMartinLutherKingJr , "2015-01-19" , "2015-01-19" ),
143
+ (USMartinLutherKingJr , "2015-01-19" , [ Timestamp ( "2015-01-19" )] ),
160
144
(USPresidentsDay , datetime (2015 , 7 , 1 ), []),
161
- (USPresidentsDay , "2015-02-16" , "2015-02-16" ),
145
+ (USPresidentsDay , "2015-02-16" , [ Timestamp ( "2015-02-16" )] ),
162
146
(GoodFriday , datetime (2015 , 7 , 1 ), []),
163
- (GoodFriday , "2015-04-03" , "2015-04-03" ),
164
- (EasterMonday , "2015-04-06" , "2015-04-06" ),
147
+ (GoodFriday , "2015-04-03" , [ Timestamp ( "2015-04-03" )] ),
148
+ (EasterMonday , "2015-04-06" , [ Timestamp ( "2015-04-06" )] ),
165
149
(EasterMonday , datetime (2015 , 7 , 1 ), []),
166
150
(EasterMonday , "2015-04-05" , []),
167
- ("New Year's Day" , "2015-01-01" , "2015-01-01" ),
168
- ("New Year's Day" , "2010-12-31" , "2010-12-31" ),
151
+ ("New Year's Day" , "2015-01-01" , [ Timestamp ( "2015-01-01" )] ),
152
+ ("New Year's Day" , "2010-12-31" , [ Timestamp ( "2010-12-31" )] ),
169
153
("New Year's Day" , datetime (2015 , 7 , 1 ), []),
170
154
("New Year's Day" , "2011-01-01" , []),
171
- ("Independence Day" , "2015-07-03" , "2015-07-03" ),
155
+ ("Independence Day" , "2015-07-03" , [ Timestamp ( "2015-07-03" )] ),
172
156
("Independence Day" , datetime (2015 , 7 , 1 ), []),
173
157
("Independence Day" , "2015-07-04" , []),
174
- ("Veterans Day" , "2012-11-12" , "2012-11-12" ),
158
+ ("Veterans Day" , "2012-11-12" , [ Timestamp ( "2012-11-12" )] ),
175
159
("Veterans Day" , datetime (2015 , 7 , 1 ), []),
176
160
("Veterans Day" , "2012-11-11" , []),
177
- ("Christmas Day" , "2011-12-26" , "2011-12-26" ),
161
+ ("Christmas Day" , "2011-12-26" , [ Timestamp ( "2011-12-26" )] ),
178
162
("Christmas Day" , datetime (2015 , 7 , 1 ), []),
179
163
("Christmas Day" , "2011-12-25" , []),
180
164
("Juneteenth National Independence Day" , "2020-06-19" , []),
181
- ("Juneteenth National Independence Day" , "2021-06-18" , "2021-06-18" ),
165
+ (
166
+ "Juneteenth National Independence Day" ,
167
+ "2021-06-18" ,
168
+ [Timestamp ("2021-06-18" )],
169
+ ),
182
170
("Juneteenth National Independence Day" , "2022-06-19" , []),
183
- ("Juneteenth National Independence Day" , "2022-06-20" , "2022-06-20" ),
171
+ (
172
+ "Juneteenth National Independence Day" ,
173
+ "2022-06-20" ,
174
+ [Timestamp ("2022-06-20" )],
175
+ ),
184
176
],
185
177
)
186
178
def test_holidays_within_dates (holiday , start , expected ):
@@ -193,10 +185,12 @@ def test_holidays_within_dates(holiday, start, expected):
193
185
calendar = get_calendar ("USFederalHolidayCalendar" )
194
186
holiday = calendar .rule_from_name (holiday )
195
187
196
- if isinstance (expected , str ):
197
- expected = [Timestamp (expected )]
188
+ assert list (holiday .dates (start , start )) == expected
198
189
199
- _check_holiday_results (holiday , start , start , expected )
190
+ # Verify that timezone info is preserved.
191
+ assert list (
192
+ holiday .dates (utc .localize (Timestamp (start )), utc .localize (Timestamp (start )))
193
+ ) == [utc .localize (dt ) for dt in expected ]
200
194
201
195
202
196
@pytest .mark .parametrize (
0 commit comments