-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix bug in calculation of holidays #31416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,3 +98,14 @@ class testCalendar(AbstractHolidayCalendar): | |
Sat_before_Labor_Day_2031 = to_datetime("2031-08-30") | ||
next_working_day = Sat_before_Labor_Day_2031 + 0 * workDay | ||
assert next_working_day == to_datetime("2031-09-02") | ||
|
||
|
||
def test_no_holidays_calendar(): | ||
# Test for issue #31415 | ||
|
||
class NoHolidaysCalendar(AbstractHolidayCalendar): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number here as a comment |
||
pass | ||
|
||
cal = NoHolidaysCalendar() | ||
holidays = cal.holidays(Timestamp("01-Jan-2020"), Timestamp("01-Jan-2021")) | ||
assert holidays.empty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you use tm.assert_series_equal here and construct an empty Series with a DTI? |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ | |||||||||
|
||||||||||
from pandas.errors import PerformanceWarning | ||||||||||
|
||||||||||
from pandas import DateOffset, Series, Timestamp, date_range | ||||||||||
from pandas import DateOffset, DatetimeIndex, Series, Timestamp, concat, date_range | ||||||||||
|
||||||||||
from pandas.tseries.offsets import Day, Easter | ||||||||||
|
||||||||||
|
@@ -406,17 +406,14 @@ def holidays(self, start=None, end=None, return_name=False): | |||||||||
start = Timestamp(start) | ||||||||||
end = Timestamp(end) | ||||||||||
|
||||||||||
holidays = None | ||||||||||
# If we don't have a cache or the dates are outside the prior cache, we | ||||||||||
# get them again | ||||||||||
if self._cache is None or start < self._cache[0] or end > self._cache[1]: | ||||||||||
for rule in self.rules: | ||||||||||
rule_holidays = rule.dates(start, end, return_name=True) | ||||||||||
|
||||||||||
if holidays is None: | ||||||||||
holidays = rule_holidays | ||||||||||
else: | ||||||||||
holidays = holidays.append(rule_holidays) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation also has the benefit of doing a single |
||||||||||
holidays = [rule.dates(start, end, return_name=True) for rule in self.rules] | ||||||||||
if holidays: | ||||||||||
holidays = concat(holidays) | ||||||||||
else: | ||||||||||
holidays = Series(index=DatetimeIndex([]), dtype=object) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't holidays typically return a DatetimeIndex ? Should maintain the same type even when empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internally, the holidays are constructed with In [7]: USFederalHolidayCalendar().holidays('01-Jan-2020', '01-Apr-2020', return_name=True)
Out[7]:
2020-01-01 New Years Day
2020-01-20 Martin Luther King Jr. Day
2020-02-17 Presidents Day
dtype: object Only if pandas/pandas/tseries/holiday.py Lines 426 to 429 in ba08390
|
||||||||||
|
||||||||||
self._cache = (start, end, holidays.sort_index()) | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ought to limit notes in the Other section if at all possible if someone wants to try to classify these better
cc @pandas-dev/pandas-core