1
- import sys
2
1
from datetime import date , datetime , timedelta
3
2
from pandas .compat import range
4
3
from pandas import compat
@@ -306,17 +305,8 @@ def _from_name(cls, suffix=None):
306
305
return cls ()
307
306
308
307
309
- class BusinessDay (SingleConstructorOffset ):
310
- """
311
- DateOffset subclass representing possibly n business days
312
- """
313
- _prefix = 'B'
314
-
315
- def __init__ (self , n = 1 , ** kwds ):
316
- self .n = int (n )
317
- self .kwds = kwds
318
- self .offset = kwds .get ('offset' , timedelta (0 ))
319
- self .normalize = kwds .get ('normalize' , False )
308
+ class BusinessMixin (object ):
309
+ """ mixin to business types to provide related functions """
320
310
321
311
# TODO: Combine this with DateOffset by defining a whitelisted set of
322
312
# attributes on each object rather than the existing behavior of iterating
@@ -345,6 +335,18 @@ def __repr__(self):
345
335
out += '>'
346
336
return out
347
337
338
+ class BusinessDay (BusinessMixin , SingleConstructorOffset ):
339
+ """
340
+ DateOffset subclass representing possibly n business days
341
+ """
342
+ _prefix = 'B'
343
+
344
+ def __init__ (self , n = 1 , ** kwds ):
345
+ self .n = int (n )
346
+ self .kwds = kwds
347
+ self .offset = kwds .get ('offset' , timedelta (0 ))
348
+ self .normalize = kwds .get ('normalize' , False )
349
+
348
350
@property
349
351
def freqstr (self ):
350
352
try :
@@ -706,7 +708,7 @@ def onOffset(cls, dt):
706
708
707
709
708
710
709
- class CustomBusinessMonthEnd (MonthOffset ):
711
+ class CustomBusinessMonthEnd (BusinessMixin , MonthOffset ):
710
712
"""
711
713
**EXPERIMENTAL** DateOffset of one custom business month
712
714
@@ -736,7 +738,6 @@ def __init__(self, n=1, **kwds):
736
738
self .offset = kwds .get ('offset' , timedelta (0 ))
737
739
self .normalize = kwds .get ('normalize' , False )
738
740
self .weekmask = kwds .get ('weekmask' , 'Mon Tue Wed Thu Fri' )
739
- holidays = kwds .get ('holidays' , [])
740
741
self .cbday = CustomBusinessDay (n = self .n ,** kwds )
741
742
self .m_offset = MonthEnd ()
742
743
@@ -762,13 +763,7 @@ def apply(self,other):
762
763
result = self .cbday .rollback (new )
763
764
return as_timestamp (result )
764
765
765
- def __repr__ (self ):
766
- if sys .version_info .major < 3 :
767
- return BusinessDay .__repr__ .__func__ (self )
768
- else :
769
- return BusinessDay .__repr__ (self )
770
-
771
- class CustomBusinessMonthBegin (MonthOffset ):
766
+ class CustomBusinessMonthBegin (BusinessMixin , MonthOffset ):
772
767
"""
773
768
**EXPERIMENTAL** DateOffset of one custom business month
774
769
@@ -798,7 +793,6 @@ def __init__(self, n=1, **kwds):
798
793
self .offset = kwds .get ('offset' , timedelta (0 ))
799
794
self .normalize = kwds .get ('normalize' , False )
800
795
self .weekmask = kwds .get ('weekmask' , 'Mon Tue Wed Thu Fri' )
801
- holidays = kwds .get ('holidays' , [])
802
796
self .cbday = CustomBusinessDay (n = self .n ,** kwds )
803
797
self .m_offset = MonthBegin ()
804
798
@@ -824,13 +818,6 @@ def apply(self,other):
824
818
result = self .cbday .rollforward (new )
825
819
return as_timestamp (result )
826
820
827
-
828
- def __repr__ (self ):
829
- if sys .version_info .major < 3 :
830
- return BusinessDay .__repr__ .__func__ (self )
831
- else :
832
- return BusinessDay .__repr__ (self )
833
-
834
821
class Week (DateOffset ):
835
822
"""
836
823
Weekly offset
0 commit comments