Skip to content

Moved caching in AbstractHolidayCalendar to the instance level #9555

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 1 commit into from
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ Bug Fixes

- Bug where dividing a dataframe containing values of type ``Decimal`` by another ``Decimal`` would raise. (:issue:`9787`)
- Bug where using DataFrames asfreq would remove the name of the index. (:issue:`9885`)
- Changed caching in ``AbstractHolidayCalendar`` to be at the instance level rather than at the class level as the latter can result in unexpected behaviour. (:issue:`9552`)
10 changes: 1 addition & 9 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class AbstractHolidayCalendar(object):
rules = []
start_date = Timestamp(datetime(1970, 1, 1))
end_date = Timestamp(datetime(2030, 12, 31))
_holiday_cache = None
_cache = None

def __init__(self, name=None, rules=None):
"""
Expand Down Expand Up @@ -351,14 +351,6 @@ def holidays(self, start=None, end=None, return_name=False):
else:
return holidays.index

@property
def _cache(self):
return self.__class__._holiday_cache

@_cache.setter
def _cache(self, values):
self.__class__._holiday_cache = values

@staticmethod
def merge_class(base, other):
"""
Expand Down
24 changes: 24 additions & 0 deletions pandas/tseries/tests/test_holiday.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from datetime import datetime
import pandas.util.testing as tm
from pandas import DatetimeIndex
from pandas.tseries.holiday import (
USFederalHolidayCalendar, USMemorialDay, USThanksgivingDay,
nearest_workday, next_monday_or_tuesday, next_monday,
Expand Down Expand Up @@ -50,6 +51,29 @@ def test_calendar(self):
self.assertEqual(list(holidays_2.to_pydatetime()),
self.holiday_list)

def test_calendar_caching(self):
# Test for issue #9552

class TestCalendar(AbstractHolidayCalendar):
def __init__(self, name=None, rules=None):
super(TestCalendar, self).__init__(
name=name,
rules=rules
)

jan1 = TestCalendar(rules=[Holiday('jan1', year=2015, month=1, day=1)])
jan2 = TestCalendar(rules=[Holiday('jan2', year=2015, month=1, day=2)])

tm.assert_index_equal(
jan1.holidays(),
DatetimeIndex(['01-Jan-2015'])
)
tm.assert_index_equal(
jan2.holidays(),
DatetimeIndex(['02-Jan-2015'])
)


class TestHoliday(tm.TestCase):

def setUp(self):
Expand Down