From 6f9e6ba97ab1db86de19cb62377c883136822045 Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Tue, 6 Aug 2019 13:34:25 -0700 Subject: [PATCH 01/11] BUG: Increase range of dates for holiday calculations --- pandas/tseries/holiday.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index 1654163d2a9e0..ebe74cec17366 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -345,8 +345,8 @@ class AbstractHolidayCalendar(metaclass=HolidayCalendarMetaClass): """ rules = [] # type: List[Holiday] - start_date = Timestamp(datetime(1970, 1, 1)) - end_date = Timestamp(datetime(2030, 12, 31)) + start_date = Timestamp(datetime(1960, 1, 1)) + end_date = Timestamp(datetime(2080, 12, 31)) _cache = None def __init__(self, name=None, rules=None): From 41e9b420743156ddf08f2787ef2777c0940447fd Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Wed, 7 Aug 2019 13:48:11 -0700 Subject: [PATCH 02/11] Increase date range in future only to avoid errors for past holidays --- pandas/tseries/holiday.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index ebe74cec17366..eb8600031439f 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -345,8 +345,8 @@ class AbstractHolidayCalendar(metaclass=HolidayCalendarMetaClass): """ rules = [] # type: List[Holiday] - start_date = Timestamp(datetime(1960, 1, 1)) - end_date = Timestamp(datetime(2080, 12, 31)) + start_date = Timestamp(datetime(1970, 1, 1)) + end_date = Timestamp(datetime(2200, 12, 31)) _cache = None def __init__(self, name=None, rules=None): From 4a7a50329340f875a9b94ea203a2e406f8ae1e5a Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Tue, 24 Sep 2019 10:24:15 -0700 Subject: [PATCH 03/11] Add test for new calendar code --- pandas/tests/tseries/holiday/test_calendar.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pandas/tests/tseries/holiday/test_calendar.py b/pandas/tests/tseries/holiday/test_calendar.py index 79c28942769f0..9bd6461651958 100644 --- a/pandas/tests/tseries/holiday/test_calendar.py +++ b/pandas/tests/tseries/holiday/test_calendar.py @@ -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 ( @@ -11,6 +11,7 @@ Timestamp, USFederalHolidayCalendar, USThanksgivingDay, + USLaborDay, get_calendar, ) @@ -81,3 +82,20 @@ 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')) From 082d67479039faf7a60005415b6079ccd0a3b0eb Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Tue, 24 Sep 2019 10:26:48 -0700 Subject: [PATCH 04/11] Add extra blank line --- pandas/tests/tseries/holiday/test_calendar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/tseries/holiday/test_calendar.py b/pandas/tests/tseries/holiday/test_calendar.py index 9bd6461651958..2706c8cf8ad2f 100644 --- a/pandas/tests/tseries/holiday/test_calendar.py +++ b/pandas/tests/tseries/holiday/test_calendar.py @@ -83,6 +83,7 @@ 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 # From 5cbfec66cd93f78fe9634a03de6dffc935511a25 Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Tue, 24 Sep 2019 10:31:06 -0700 Subject: [PATCH 05/11] Remove spaces from blank line --- pandas/tests/tseries/holiday/test_calendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/holiday/test_calendar.py b/pandas/tests/tseries/holiday/test_calendar.py index 2706c8cf8ad2f..29fcfd760f1d5 100644 --- a/pandas/tests/tseries/holiday/test_calendar.py +++ b/pandas/tests/tseries/holiday/test_calendar.py @@ -83,7 +83,7 @@ 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 # From b65d5516074dc3037a7f999bf146fd949494e035 Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Wed, 25 Sep 2019 08:51:12 -0700 Subject: [PATCH 06/11] Remove brackets from assert --- pandas/tests/tseries/holiday/test_calendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/holiday/test_calendar.py b/pandas/tests/tseries/holiday/test_calendar.py index 29fcfd760f1d5..4090badd24169 100644 --- a/pandas/tests/tseries/holiday/test_calendar.py +++ b/pandas/tests/tseries/holiday/test_calendar.py @@ -99,4 +99,4 @@ class testCalendar(AbstractHolidayCalendar): 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')) + assert next_working_day == to_datetime('2031-09-02') From aae671902f0d01d25187929818078331313ba517 Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Wed, 25 Sep 2019 10:32:22 -0700 Subject: [PATCH 07/11] Shorten line in test_categorical.py --- pandas/tests/groupby/test_categorical.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index fcc0aa3b1c015..9135d9dfa9b39 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -782,7 +782,8 @@ def test_categorical_no_compress(): def test_sort(): - # http://stackoverflow.com/questions/23814368/sorting-pandas-categorical-labels-after-groupby # noqa: E501 + # http://stackoverflow.com/questions/23814368/sorting-pandas- + # categorical-labels-after-groupby # This should result in a properly sorted Series so that the plot # has a sorted x axis # self.cat.groupby(['value_group'])['value_group'].count().plot(kind='bar') From 76565718bc351c3819c7bc4282ee87c7620298c3 Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Wed, 25 Sep 2019 11:06:32 -0700 Subject: [PATCH 08/11] Change import sort order --- pandas/tests/tseries/holiday/test_calendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/holiday/test_calendar.py b/pandas/tests/tseries/holiday/test_calendar.py index 4090badd24169..80a0dcabb2ab1 100644 --- a/pandas/tests/tseries/holiday/test_calendar.py +++ b/pandas/tests/tseries/holiday/test_calendar.py @@ -10,8 +10,8 @@ Holiday, Timestamp, USFederalHolidayCalendar, - USThanksgivingDay, USLaborDay, + USThanksgivingDay, get_calendar, ) From 1e3369c45700f58eb623c04ef1c00fefb68b2785 Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Wed, 25 Sep 2019 14:36:17 -0700 Subject: [PATCH 09/11] Reformat test_calendar.py --- pandas/tests/tseries/holiday/test_calendar.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/tests/tseries/holiday/test_calendar.py b/pandas/tests/tseries/holiday/test_calendar.py index 80a0dcabb2ab1..c122f92ed228c 100644 --- a/pandas/tests/tseries/holiday/test_calendar.py +++ b/pandas/tests/tseries/holiday/test_calendar.py @@ -91,12 +91,10 @@ def test_calendar_2031(): # Next working day after August 30 ought to be Tuesday, September 2. class testCalendar(AbstractHolidayCalendar): - rules = [ - USLaborDay, - ] + rules = [USLaborDay] cal = testCalendar() workDay = offsets.CustomBusinessDay(calendar=cal) - Sat_before_Labor_Day_2031 = to_datetime('2031-08-30') + 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') + assert next_working_day == to_datetime("2031-09-02") From cc0abbd227aa8e6e32517b0629ca27b679f83f2a Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Thu, 17 Oct 2019 16:09:23 -0700 Subject: [PATCH 10/11] Add whatsnew --- doc/source/whatsnew/v0.25.2.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/whatsnew/v0.25.2.rst b/doc/source/whatsnew/v0.25.2.rst index 14682b706f924..2480b95712ad3 100644 --- a/doc/source/whatsnew/v0.25.2.rst +++ b/doc/source/whatsnew/v0.25.2.rst @@ -102,6 +102,9 @@ Other - Compatibility with Python 3.8 in :meth:`DataFrame.query` (:issue:`27261`) - Fix to ensure that tab-completion in an IPython console does not raise warnings for deprecated attributes (:issue:`27900`). +- Fix :class:`AbstractHolidayCalendar` to return correct results for + years after 2030 (now goes up to 2200) (:issue:`27790`) + .. _whatsnew_0.252.contributors: From 66db79f91594c25d3db0fee169dfa11f5ce69385 Mon Sep 17 00:00:00 2001 From: Richard Stanton Date: Fri, 18 Oct 2019 10:15:45 -0700 Subject: [PATCH 11/11] Move whatsnew message --- doc/source/whatsnew/v0.25.2.rst | 3 --- doc/source/whatsnew/v1.0.0.rst | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.25.2.rst b/doc/source/whatsnew/v0.25.2.rst index e4256bf956ede..a99751f9bab9f 100644 --- a/doc/source/whatsnew/v0.25.2.rst +++ b/doc/source/whatsnew/v0.25.2.rst @@ -40,9 +40,6 @@ Other - Compatibility with Python 3.8 in :meth:`DataFrame.query` (:issue:`27261`) - Fix to ensure that tab-completion in an IPython console does not raise warnings for deprecated attributes (:issue:`27900`). -- Fix :class:`AbstractHolidayCalendar` to return correct results for - years after 2030 (now goes up to 2200) (:issue:`27790`) - .. _whatsnew_0.252.contributors: diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 48c1173a372a7..78ebdb985edad 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -409,6 +409,9 @@ Other - Bug in :meth:`Series.diff` where a boolean series would incorrectly raise a ``TypeError`` (:issue:`17294`) - :meth:`Series.append` will no longer raise a ``TypeError`` when passed a tuple of ``Series`` (:issue:`28410`) - Fix corrupted error message when calling ``pandas.libs._json.encode()`` on a 0d array (:issue:`18878`) +- Fix :class:`AbstractHolidayCalendar` to return correct results for + years after 2030 (now goes up to 2200) (:issue:`27790`) + .. _whatsnew_1000.contributors: