@@ -382,6 +382,7 @@ frequency increment. Specific offset logic like "month", "business day", or
382
382
383
383
DateOffset, "Generic offset class, defaults to 1 calendar day"
384
384
BDay, "business day (weekday)"
385
+ CDay, "custom business day (experimental)"
385
386
Week, "one week, optionally anchored on a day of the week"
386
387
WeekOfMonth, "the x-th day of the y-th week of each month"
387
388
MonthEnd, "calendar month end"
@@ -477,6 +478,54 @@ Another example is parameterizing ``YearEnd`` with the specific ending month:
477
478
478
479
.. _timeseries.alias :
479
480
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
+
480
529
Offset Aliases
481
530
~~~~~~~~~~~~~~
482
531
@@ -489,6 +538,7 @@ frequencies. We will refer to these aliases as *offset aliases*
489
538
:widths: 15, 100
490
539
491
540
"B", "business day frequency"
541
+ "C", "custom business day frequency (experimental)"
492
542
"D", "calendar day frequency"
493
543
"W", "weekly frequency"
494
544
"M", "month end frequency"
0 commit comments