@@ -310,8 +310,53 @@ def is_on_offset(self, dt):
310
310
# TODO, see #1395
311
311
return True
312
312
313
+ def _repr_attrs (self ) -> str :
314
+ # The DateOffset class differs from other classes in that members
315
+ # of self._attributes may not be defined, so we have to use __dict__
316
+ # instead.
317
+ exclude = {"n" , "inc" , "normalize" }
318
+ attrs = []
319
+ for attr in sorted (self .__dict__ ):
320
+ if attr .startswith ("_" ) or attr == "kwds" :
321
+ continue
322
+ elif attr not in exclude :
323
+ value = getattr (self , attr )
324
+ attrs .append (f"{ attr } ={ value } " )
325
+
326
+ out = ""
327
+ if attrs :
328
+ out += ": " + ", " .join (attrs )
329
+ return out
313
330
314
- class BusinessDay (BusinessMixin , SingleConstructorOffset ):
331
+ @cache_readonly
332
+ def _params (self ):
333
+ """
334
+ Returns a tuple containing all of the attributes needed to evaluate
335
+ equality between two DateOffset objects.
336
+ """
337
+ # The DateOffset class differs from other classes in that members
338
+ # of self._attributes may not be defined, so we have to use __dict__
339
+ # instead.
340
+ all_paras = self .__dict__ .copy ()
341
+ all_paras ["n" ] = self .n
342
+ all_paras ["normalize" ] = self .normalize
343
+ for key in self .__dict__ :
344
+ if key not in all_paras :
345
+ # cython attributes are not in __dict__
346
+ all_paras [key ] = getattr (self , key )
347
+
348
+ if "holidays" in all_paras and not all_paras ["holidays" ]:
349
+ all_paras .pop ("holidays" )
350
+ exclude = ["kwds" , "name" , "calendar" ]
351
+ attrs = [
352
+ (k , v ) for k , v in all_paras .items () if (k not in exclude ) and (k [0 ] != "_" )
353
+ ]
354
+ attrs = sorted (set (attrs ))
355
+ params = tuple ([str (type (self ))] + attrs )
356
+ return params
357
+
358
+
359
+ class BusinessDay (BusinessMixin ):
315
360
"""
316
361
DateOffset subclass representing possibly n business days.
317
362
"""
@@ -796,6 +841,22 @@ def __init__(
796
841
BusinessHour .__init__ (self , n , normalize , start = start , end = end , offset = offset )
797
842
CustomMixin .__init__ (self , weekmask , holidays , calendar )
798
843
844
+ def __reduce__ (self ):
845
+ # None for self.calendar bc np.busdaycalendar doesnt pickle nicely
846
+ return (
847
+ type (self ),
848
+ (
849
+ self .n ,
850
+ self .normalize ,
851
+ self .weekmask ,
852
+ self .holidays ,
853
+ None ,
854
+ self .start ,
855
+ self .end ,
856
+ self .offset ,
857
+ ),
858
+ )
859
+
799
860
800
861
# ---------------------------------------------------------------------
801
862
# Month-Based Offset Classes
@@ -1286,6 +1347,9 @@ def __init__(self, n=1, normalize=False, week=0, weekday=0):
1286
1347
if self .week < 0 or self .week > 3 :
1287
1348
raise ValueError (f"Week must be 0<=week<=3, got { self .week } " )
1288
1349
1350
+ def __reduce__ (self ):
1351
+ return type (self ), (self .n , self .normalize , self .week , self .weekday )
1352
+
1289
1353
def _get_offset_day (self , other : datetime ) -> int :
1290
1354
"""
1291
1355
Find the day in the same month as other that has the same
@@ -1345,6 +1409,9 @@ def __init__(self, n=1, normalize=False, weekday=0):
1345
1409
raise ValueError ("N cannot be 0" )
1346
1410
object .__setattr__ (self , "week" , - 1 )
1347
1411
1412
+ def __reduce__ (self ):
1413
+ return type (self ), (self .n , self .normalize , self .weekday )
1414
+
1348
1415
def _get_offset_day (self , other : datetime ) -> int :
1349
1416
"""
1350
1417
Find the day in the same month as other that has the same
0 commit comments