Skip to content

Commit 8ccdf48

Browse files
clearfjreback
authored andcommitted
BUG: Fix MLK and Memorial day date representations, #9760
1 parent 914b5dd commit 8ccdf48

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

doc/source/whatsnew/v0.17.0.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,6 @@ Performance Improvements
591591

592592
Bug Fixes
593593
~~~~~~~~~
594-
595-
596594
- Bug in ``DataFrame.to_html(index=False)`` renders unnecessary ``name`` row (:issue:`10344`)
597595
- Bug in ``DataFrame.apply`` when function returns categorical series. (:issue:`9573`)
598596
- Bug in ``to_datetime`` with invalid dates and formats supplied (:issue:`10154`)
@@ -607,6 +605,7 @@ Bug Fixes
607605
- Bug in ``pd.rolling_*`` where ``Series.name`` would be lost in the output (:issue:`10565`)
608606
- Bug in ``stack`` when index or columns are not unique. (:issue:`10417`)
609607
- Bug in setting a Panel when an axis has a multi-index (:issue:`10360`)
608+
- Bug in ``USFederalHolidayCalendar`` where ``USMemorialDay`` and ``USMartinLutherKingJr`` were incorrect (:issue:`10278` and :issue:`9760` )
610609

611610

612611

pandas/tests/test_tseries.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
import pandas.lib as lib
1010
import pandas._period as period
1111
import pandas.algos as algos
12-
from pandas.tseries.holiday import Holiday, SA, next_monday
12+
from pandas.tseries.holiday import Holiday, SA, next_monday,USMartinLutherKingJr,USMemorialDay,AbstractHolidayCalendar
13+
import datetime
14+
15+
1316
from pandas import DateOffset
1417

1518

@@ -751,6 +754,28 @@ def test_get_period_field_raises_on_out_of_range(self):
751754
def test_get_period_field_array_raises_on_out_of_range(self):
752755
self.assertRaises(ValueError, period.get_period_field_arr, -1, np.empty(1), 0)
753756

757+
class TestFederalHolidayCalendar(tm.TestCase):
758+
# Test for issue 10278
759+
def test_no_mlk_before_1984(self):
760+
class MLKCalendar(AbstractHolidayCalendar):
761+
rules=[USMartinLutherKingJr]
762+
holidays = MLKCalendar().holidays(start='1984', end='1988').to_pydatetime().tolist()
763+
# Testing to make sure holiday is not incorrectly observed before 1986
764+
self.assertEqual(holidays, [datetime.datetime(1986, 1, 20, 0, 0), datetime.datetime(1987, 1, 19, 0, 0)])
765+
766+
def test_memorial_day(self):
767+
class MemorialDay(AbstractHolidayCalendar):
768+
rules=[USMemorialDay]
769+
holidays = MemorialDay().holidays(start='1971', end='1980').to_pydatetime().tolist()
770+
# Fixes 5/31 error and checked manually against wikipedia
771+
self.assertEqual(holidays, [datetime.datetime(1971, 5, 31, 0, 0), datetime.datetime(1972, 5, 29, 0, 0),
772+
datetime.datetime(1973, 5, 28, 0, 0), datetime.datetime(1974, 5, 27, 0, 0),
773+
datetime.datetime(1975, 5, 26, 0, 0), datetime.datetime(1976, 5, 31, 0, 0),
774+
datetime.datetime(1977, 5, 30, 0, 0), datetime.datetime(1978, 5, 29, 0, 0),
775+
datetime.datetime(1979, 5, 28, 0, 0)])
776+
777+
778+
754779

755780
class TestHolidayConflictingArguments(tm.TestCase):
756781

pandas/tseries/holiday.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,15 @@ def merge(self, other, inplace=False):
405405
else:
406406
return holidays
407407

408-
USMemorialDay = Holiday('MemorialDay', month=5, day=24,
409-
offset=DateOffset(weekday=MO(1)))
408+
USMemorialDay = Holiday('MemorialDay', month=5, day=31,
409+
offset=DateOffset(weekday=MO(-1)))
410410
USLaborDay = Holiday('Labor Day', month=9, day=1,
411411
offset=DateOffset(weekday=MO(1)))
412412
USColumbusDay = Holiday('Columbus Day', month=10, day=1,
413413
offset=DateOffset(weekday=MO(2)))
414414
USThanksgivingDay = Holiday('Thanksgiving', month=11, day=1,
415415
offset=DateOffset(weekday=TH(4)))
416-
USMartinLutherKingJr = Holiday('Dr. Martin Luther King Jr.', month=1, day=1,
416+
USMartinLutherKingJr = Holiday('Dr. Martin Luther King Jr.', start_date=datetime(1986,1,1), month=1, day=1,
417417
offset=DateOffset(weekday=MO(3)))
418418
USPresidentsDay = Holiday('President''s Day', month=2, day=1,
419419
offset=DateOffset(weekday=MO(3)))

0 commit comments

Comments
 (0)