Skip to content
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

Bug in AbstractHolidayCalendar.holidays #31415

Closed
dhirschfeld opened this issue Jan 29, 2020 · 1 comment · Fixed by #31416
Closed

Bug in AbstractHolidayCalendar.holidays #31415

dhirschfeld opened this issue Jan 29, 2020 · 1 comment · Fixed by #31416
Labels
Bug Frequency DateOffsets
Milestone

Comments

@dhirschfeld
Copy link
Contributor

...when there are no rules.

from pandas.tseries.holiday import AbstractHolidayCalendar

class ExampleCalendar(AbstractHolidayCalendar):
    pass

cal = ExampleCalendar()
In [58]: cal.holidays(pd.Timestamp('01-Jan-2020'), pd.Timestamp('01-Jan-2021'))
Traceback (most recent call last):

  File "<ipython-input-58-022244d4e794>", line 1, in <module>
    cal.holidays(pd.Timestamp('01-Jan-2020'), pd.Timestamp('01-Jan-2021'))

  File "C:\Users\dhirschf\envs\dev\lib\site-packages\pandas\tseries\holiday.py", line 422, in holidays
    self._cache = (start, end, holidays.sort_index())

AttributeError: 'NoneType' object has no attribute 'sort_index'

In [59]: pd.__version__
Out[59]: '0.25.3'
@dhirschfeld
Copy link
Contributor Author

As can be seen below:

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)
self._cache = (start, end, holidays.sort_index())

when self.rules is empty

In [61]: cal.rules
Out[61]: []

You drop through the loop to L421:

self._cache = (start, end, holidays.sort_index()) 

where holidays remains unchanged from being set to None before the loop on L409.

dhirschfeld added a commit to dhirschfeld/pandas that referenced this issue Jan 29, 2020
dhirschfeld added a commit to dhirschfeld/pandas that referenced this issue Jan 29, 2020
dhirschfeld added a commit to dhirschfeld/pandas that referenced this issue Jan 29, 2020
dhirschfeld pushed a commit to dhirschfeld/pandas that referenced this issue Jan 30, 2020
dhirschfeld pushed a commit to dhirschfeld/pandas that referenced this issue Jan 30, 2020
dhirschfeld added a commit to dhirschfeld/pandas that referenced this issue Jan 30, 2020
dhirschfeld pushed a commit to dhirschfeld/pandas that referenced this issue Jan 30, 2020
@jreback jreback added this to the 1.1 milestone Feb 1, 2020
@jreback jreback added Bug Frequency DateOffsets labels Feb 1, 2020
dhirschfeld added a commit to dhirschfeld/pandas that referenced this issue Feb 2, 2020
dhirschfeld pushed a commit to dhirschfeld/pandas that referenced this issue Feb 2, 2020
dhirschfeld pushed a commit to dhirschfeld/pandas that referenced this issue Feb 3, 2020
dhirschfeld pushed a commit to dhirschfeld/pandas that referenced this issue Feb 3, 2020
dhirschfeld pushed a commit to dhirschfeld/pandas that referenced this issue Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants