Skip to content

Commit 94d41a8

Browse files
Tobias BrandtTobias Brandt
Tobias Brandt
authored and
Tobias Brandt
committed
DOC: Added notes on the CustomBusinessDay class to the release notes as well as
the TimeSeries documentation. DOC: Added more cautionary warnings about the experimental nature of the current state of the CustomBusinessDay class.
1 parent db7cd2e commit 94d41a8

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

doc/source/timeseries.rst

+50
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ frequency increment. Specific offset logic like "month", "business day", or
382382

383383
DateOffset, "Generic offset class, defaults to 1 calendar day"
384384
BDay, "business day (weekday)"
385+
CDay, "custom business day (experimental)"
385386
Week, "one week, optionally anchored on a day of the week"
386387
WeekOfMonth, "the x-th day of the y-th week of each month"
387388
MonthEnd, "calendar month end"
@@ -477,6 +478,54 @@ Another example is parameterizing ``YearEnd`` with the specific ending month:
477478
478479
.. _timeseries.alias:
479480

481+
Custom Business Days (Experimental)
482+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
483+
484+
The ``CDay`` or ``CustomBusinessDay`` class provides a parametric
485+
``BusinessDay`` class which can be used to create customized business day
486+
calendars which account for local holidays and local weekend conventions.
487+
488+
.. ipython:: python
489+
490+
from pandas.tseries.offsets import CustomBusinessDay
491+
# As an interesting example, let's look at Egypt where
492+
# a Friday-Saturday weekend is observed.
493+
weekmask_egypt = 'Sun Mon Tue Wed Thu'
494+
# They also observe International Workers' Day so let's
495+
# add that for a couple of years
496+
holidays = ['2012-05-01', datetime(2013, 5, 1), np.datetime64('2014-05-01')]
497+
bday_egypt = CustomBusinessDay(holidays=holidays, weekmask=weekmask_egypt)
498+
dt = datetime(2013, 4, 30)
499+
print dt + 2 * bday_egypt
500+
dts = date_range(dt, periods=5, freq=bday_egypt).to_series()
501+
print dts
502+
print Series(dts.weekday, dts).map(Series('Mon Tue Wed Thu Fri Sat Sun'.split()))
503+
504+
.. note::
505+
506+
The frequency string 'C' is used to indicate that a CustomBusinessDay
507+
DateOffset is used, it is important to note that since CustomBusinessDay is
508+
a parameterised type, instances of CustomBusinessDay may differ and this is
509+
not detectable from the 'C' frequency string. The user therefore needs to
510+
ensure that the 'C' frequency string is used consistently within the user's
511+
application.
512+
513+
514+
.. note::
515+
516+
This uses the ``numpy.busdaycalendar`` API introduced in Numpy 1.7 and
517+
therefore requires Numpy 1.7.0 or newer.
518+
519+
.. warning::
520+
521+
There are known problems with the timezone handling in Numpy 1.7 and users
522+
should therefore use this **experimental(!)** feature with caution and at
523+
their own risk.
524+
525+
To the extent that the ``datetime64`` and ``busdaycalendar`` APIs in Numpy
526+
have to change to fix the timezone issues, the behaviour of the
527+
``CustomBusinessDay`` class may have to change in future versions.
528+
480529
Offset Aliases
481530
~~~~~~~~~~~~~~
482531

@@ -489,6 +538,7 @@ frequencies. We will refer to these aliases as *offset aliases*
489538
:widths: 15, 100
490539

491540
"B", "business day frequency"
541+
"C", "custom business day frequency (experimental)"
492542
"D", "calendar day frequency"
493543
"W", "weekly frequency"
494544
"M", "month end frequency"

doc/source/v0.11.1.txt

+26
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,32 @@ Other Enhancements
319319
- DatetimeIndexes no longer try to convert mixed-integer indexes during join
320320
operations (:issue:`3877`)
321321

322+
Experimental Features
323+
~~~~~~~~~~~~~~~~~~~~~
324+
325+
- Added experimental ``CustomBusinessDay`` class to support ``DateOffsets``
326+
with custom holiday calendars and custom weekmasks. (GH2301_)
327+
328+
.. note::
329+
330+
This uses the ``numpy.busdaycalendar`` API introduced in Numpy 1.7 and
331+
therefore requires Numpy 1.7.0 or newer.
332+
333+
.. ipython:: python
334+
335+
from pandas.tseries.offsets import CustomBusinessDay
336+
# As an interesting example, let's look at Egypt where
337+
# a Friday-Saturday weekend is observed.
338+
weekmask_egypt = 'Sun Mon Tue Wed Thu'
339+
# They also observe International Workers' Day so let's
340+
# add that for a couple of years
341+
holidays = ['2012-05-01', datetime(2013, 5, 1), np.datetime64('2014-05-01')]
342+
bday_egypt = CustomBusinessDay(holidays=holidays, weekmask=weekmask_egypt)
343+
dt = datetime(2013, 4, 30)
344+
print dt + 2 * bday_egypt
345+
dts = date_range(dt, periods=5, freq=bday_egypt).to_series()
346+
print Series(dts.weekday, dts).map(Series('Mon Tue Wed Thu Fri Sat Sun'.split()))
347+
322348
Bug Fixes
323349
~~~~~~~~~
324350

pandas/tseries/index.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,13 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
17431743
def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
17441744
normalize=True, name=None, **kwargs):
17451745
"""
1746-
Return a fixed frequency datetime index, with CustomBusinessDay as the
1747-
default frequency
1746+
**EXPERIMENTAL** Return a fixed frequency datetime index, with
1747+
CustomBusinessDay as the default frequency
1748+
1749+
.. warning:: EXPERIMENTAL
1750+
1751+
The CustomBusinessDay class is not officially supported and the API is
1752+
likely to change in future versions. Use this at your own risk.
17481753
17491754
Parameters
17501755
----------

pandas/tseries/offsets.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,13 @@ def onOffset(cls, dt):
363363

364364
class CustomBusinessDay(BusinessDay):
365365
"""
366-
DateOffset subclass representing possibly n business days excluding
367-
holidays
366+
**EXPERIMENTAL** DateOffset subclass representing possibly n business days
367+
excluding holidays
368+
369+
.. warning:: EXPERIMENTAL
370+
371+
This class is not officially supported and the API is likely to change
372+
in future versions. Use this at your own risk.
368373
369374
Parameters
370375
----------

0 commit comments

Comments
 (0)