Skip to content

Commit a755700

Browse files
authored
CLN: test_holiday (pandas-dev#44808)
1 parent 6ceba52 commit a755700

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

pandas/tests/tseries/holiday/test_holiday.py

+36-42
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,6 @@
2626
)
2727

2828

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-
5229
@pytest.mark.parametrize(
5330
"holiday,start_date,end_date,expected",
5431
[
@@ -141,46 +118,61 @@ def _check_holiday_results(holiday, start, end, expected):
141118
],
142119
)
143120
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]
145129

146130

147131
@pytest.mark.parametrize(
148132
"holiday,start,expected",
149133
[
150134
(USMemorialDay, datetime(2015, 7, 1), []),
151-
(USMemorialDay, "2015-05-25", "2015-05-25"),
135+
(USMemorialDay, "2015-05-25", [Timestamp("2015-05-25")]),
152136
(USLaborDay, datetime(2015, 7, 1), []),
153-
(USLaborDay, "2015-09-07", "2015-09-07"),
137+
(USLaborDay, "2015-09-07", [Timestamp("2015-09-07")]),
154138
(USColumbusDay, datetime(2015, 7, 1), []),
155-
(USColumbusDay, "2015-10-12", "2015-10-12"),
139+
(USColumbusDay, "2015-10-12", [Timestamp("2015-10-12")]),
156140
(USThanksgivingDay, datetime(2015, 7, 1), []),
157-
(USThanksgivingDay, "2015-11-26", "2015-11-26"),
141+
(USThanksgivingDay, "2015-11-26", [Timestamp("2015-11-26")]),
158142
(USMartinLutherKingJr, datetime(2015, 7, 1), []),
159-
(USMartinLutherKingJr, "2015-01-19", "2015-01-19"),
143+
(USMartinLutherKingJr, "2015-01-19", [Timestamp("2015-01-19")]),
160144
(USPresidentsDay, datetime(2015, 7, 1), []),
161-
(USPresidentsDay, "2015-02-16", "2015-02-16"),
145+
(USPresidentsDay, "2015-02-16", [Timestamp("2015-02-16")]),
162146
(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")]),
165149
(EasterMonday, datetime(2015, 7, 1), []),
166150
(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")]),
169153
("New Year's Day", datetime(2015, 7, 1), []),
170154
("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")]),
172156
("Independence Day", datetime(2015, 7, 1), []),
173157
("Independence Day", "2015-07-04", []),
174-
("Veterans Day", "2012-11-12", "2012-11-12"),
158+
("Veterans Day", "2012-11-12", [Timestamp("2012-11-12")]),
175159
("Veterans Day", datetime(2015, 7, 1), []),
176160
("Veterans Day", "2012-11-11", []),
177-
("Christmas Day", "2011-12-26", "2011-12-26"),
161+
("Christmas Day", "2011-12-26", [Timestamp("2011-12-26")]),
178162
("Christmas Day", datetime(2015, 7, 1), []),
179163
("Christmas Day", "2011-12-25", []),
180164
("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+
),
182170
("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+
),
184176
],
185177
)
186178
def test_holidays_within_dates(holiday, start, expected):
@@ -193,10 +185,12 @@ def test_holidays_within_dates(holiday, start, expected):
193185
calendar = get_calendar("USFederalHolidayCalendar")
194186
holiday = calendar.rule_from_name(holiday)
195187

196-
if isinstance(expected, str):
197-
expected = [Timestamp(expected)]
188+
assert list(holiday.dates(start, start)) == expected
198189

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]
200194

201195

202196
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)