Skip to content

Commit 0d62439

Browse files
rockgjeffreystarr
authored andcommitted
Additional documentation for holiday calendars and minor correction to start/end date logic.
1 parent e762e41 commit 0d62439

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

doc/source/timeseries.rst

+37-11
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ calendars which account for local holidays and local weekend conventions.
541541
holidays = ['2012-05-01', datetime(2013, 5, 1), np.datetime64('2014-05-01')]
542542
bday_egypt = CustomBusinessDay(holidays=holidays, weekmask=weekmask_egypt)
543543
dt = datetime(2013, 4, 30)
544-
print(dt + 2 * bday_egypt)
544+
dt + 2 * bday_egypt
545545
dts = date_range(dt, periods=5, freq=bday_egypt).to_series()
546-
print(dts)
547-
print(Series(dts.weekday, dts).map(Series('Mon Tue Wed Thu Fri Sat Sun'.split())))
546+
dts
547+
Series(dts.weekday, dts).map(Series('Mon Tue Wed Thu Fri Sat Sun'.split()))
548548
549549
As of v0.14 holiday calendars can be used to provide the list of holidays. See the
550550
:ref:`holiday calendar<timeseries.holiday>` section for more information.
@@ -553,8 +553,10 @@ As of v0.14 holiday calendars can be used to provide the list of holidays. See
553553
554554
from pandas.tseries.holiday import USFederalHolidayCalendar
555555
bday_us = CustomBusinessDay(calendar=USFederalHolidayCalendar())
556-
dt = datetime(2014, 1, 17) #Friday before MLK Day
557-
print(dt + bday_us) #Tuesday after MLK Day
556+
# Friday before MLK Day
557+
dt = datetime(2014, 1, 17)
558+
# Tuesday after MLK Day (Monday is skipped because it's a holiday)
559+
dt + bday_us
558560
559561
560562
.. note::
@@ -767,12 +769,36 @@ An example of how holidays and holiday calendars are defined:
767769
offset=DateOffset(weekday=MO(2))), #same as 2*Week(weekday=2)
768770
]
769771
cal = ExampleCalendar()
770-
datetime(2012, 5, 25) + CustomBusinessDay(calendar=cal)
771-
cal.holidays(datetime(2012, 1, 1), datetime(2012, 12, 31))#holiday list
772-
AbstractHolidayCalendar.start_date #default start date of range
773-
AbstractHolidayCalendar.end_date #default end date of range
774-
AbstractHolidayCalendar.start_date = datetime(2012, 1, 1)#or Timestamp
775-
AbstractHolidayCalendar.end_date = datetime(2012, 12, 31)#or Timestamp
772+
cal.holidays(datetime(2012, 1, 1), datetime(2012, 12, 31))
773+
774+
Using this calendar, creating an index or doing offset arithmetic skips weekends
775+
and holidays (i.e., Memorial Day/July 4th).
776+
777+
.. ipython:: python
778+
779+
DatetimeIndex(start='7/1/2012', end='7/10/2012',
780+
freq=CDay(calendar=cal)).to_pydatetime()
781+
offset = CustomBusinessDay(calendar=cal)
782+
datetime(2012, 5, 25) + offset
783+
datetime(2012, 7, 3) + offset
784+
datetime(2012, 7, 3) + 2 * offset
785+
datetime(2012, 7, 6) + offset
786+
787+
Ranges are defined by the ``start_date`` and ``end_date`` class attributes
788+
of ``AbstractHolidayCalendar``. The defaults are below.
789+
790+
.. ipython:: python
791+
792+
AbstractHolidayCalendar.start_date
793+
AbstractHolidayCalendar.end_date
794+
795+
These dates can be overwritten by setting the attributes as
796+
datetime/Timestamp/string.
797+
798+
.. ipython:: python
799+
800+
AbstractHolidayCalendar.start_date = datetime(2012, 1, 1)
801+
AbstractHolidayCalendar.end_date = datetime(2012, 12, 31)
776802
cal.holidays()
777803
778804
Every calendar class is accessible by name using the ``get_calendar`` function

pandas/tseries/holiday.py

-7
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,6 @@ def holidays(self, start=None, end=None, return_name=False):
225225
-------
226226
DatetimeIndex of holidays
227227
"""
228-
#FIXME: Where should the default limits exist?
229-
if start is None:
230-
start = datetime(1970, 1, 1)
231-
232-
if end is None:
233-
end = datetime(2030, 12, 31)
234-
235228
if self.rules is None:
236229
raise Exception('Holiday Calendar %s does not have any '\
237230
'rules specified' % self.name)

0 commit comments

Comments
 (0)