Skip to content

BUG: Increase range of dates for holiday calculations #27790

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

Merged
merged 16 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pandas/tests/tseries/holiday/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from pandas import DatetimeIndex
from pandas import DatetimeIndex, offsets, to_datetime
import pandas.util.testing as tm

from pandas.tseries.holiday import (
Expand All @@ -11,6 +11,7 @@
Timestamp,
USFederalHolidayCalendar,
USThanksgivingDay,
USLaborDay,
get_calendar,
)

Expand Down Expand Up @@ -81,3 +82,21 @@ def test_calendar_observance_dates():
def test_rule_from_name():
us_fed_cal = get_calendar("USFederalHolidayCalendar")
assert us_fed_cal.rule_from_name("Thanksgiving") == USThanksgivingDay


def test_calendar_2031():
# See gh-27790
#
# Labor Day 2031 is on September 1. Saturday before is August 30.
# Next working day after August 30 ought to be Tuesday, September 2.

class testCalendar(AbstractHolidayCalendar):
rules = [
USLaborDay,
]

cal = testCalendar()
workDay = offsets.CustomBusinessDay(calendar=cal)
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'))
Copy link
Member

@gfyoung gfyoung Sep 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And while you're at it: can you remove the parentheses here?

We use bare assert statements (see the test above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. I'll wait until tomorrow, though. Merging master had no effect just now, so it seems the errors are in the current version.

Copy link
Contributor Author

@rhstanton rhstanton Sep 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After pushing , the checks now give me an error message like this:

##[error]Bash exited with code '1'.

But I have no idea what to do about fixing this.

Copy link
Member

@gfyoung gfyoung Sep 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=17967

It looks like the black pandas lint check is failing (https://pypi.org/project/black/).

You are so close!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformatted that file using black. Let's see if it works now. I'm hoping it's a bit quicker next time...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It passed all tests!

2 changes: 1 addition & 1 deletion pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class AbstractHolidayCalendar(metaclass=HolidayCalendarMetaClass):

rules = [] # type: List[Holiday]
start_date = Timestamp(datetime(1970, 1, 1))
end_date = Timestamp(datetime(2030, 12, 31))
end_date = Timestamp(datetime(2200, 12, 31))
_cache = None

def __init__(self, name=None, rules=None):
Expand Down