|  | 
| 4 | 4 |  datetime, | 
| 5 | 5 |  timedelta, | 
| 6 | 6 | ) | 
|  | 7 | +from typing import Callable | 
| 7 | 8 | import warnings | 
| 8 | 9 | 
 | 
| 9 | 10 | from dateutil.relativedelta import ( | 
|  | 
| 17 | 18 | ) | 
| 18 | 19 | import numpy as np | 
| 19 | 20 | 
 | 
|  | 21 | +from pandas._libs.tslibs.offsets import BaseOffset | 
| 20 | 22 | from pandas.errors import PerformanceWarning | 
| 21 | 23 | 
 | 
| 22 | 24 | from pandas import ( | 
| @@ -159,24 +161,34 @@ def __init__( | 
| 159 | 161 |  year=None, | 
| 160 | 162 |  month=None, | 
| 161 | 163 |  day=None, | 
| 162 |  | - offset=None, | 
| 163 |  | - observance=None, | 
|  | 164 | + offset: BaseOffset | list[BaseOffset] | None = None, | 
|  | 165 | + observance: Callable | None = None, | 
| 164 | 166 |  start_date=None, | 
| 165 | 167 |  end_date=None, | 
| 166 |  | - days_of_week=None, | 
|  | 168 | + days_of_week: tuple | None = None, | 
| 167 | 169 |  ) -> None: | 
| 168 | 170 |  """ | 
| 169 | 171 |  Parameters | 
| 170 | 172 |  ---------- | 
| 171 | 173 |  name : str | 
| 172 | 174 |  Name of the holiday , defaults to class name | 
| 173 |  | - offset : array of pandas.tseries.offsets or | 
| 174 |  | - class from pandas.tseries.offsets | 
| 175 |  | - computes offset from date | 
| 176 |  | - observance: function | 
| 177 |  | - computes when holiday is given a pandas Timestamp | 
| 178 |  | - days_of_week: | 
| 179 |  | - provide a tuple of days e.g (0,1,2,3,) for Monday Through Thursday | 
|  | 175 | + year : int, default None | 
|  | 176 | + Year of the holiday | 
|  | 177 | + month : int, default None | 
|  | 178 | + Month of the holiday | 
|  | 179 | + day : int, default None | 
|  | 180 | + Day of the holiday | 
|  | 181 | + offset : list of pandas.tseries.offsets or | 
|  | 182 | + class from pandas.tseries.offsets, default None | 
|  | 183 | + Computes offset from date | 
|  | 184 | + observance : function, default None | 
|  | 185 | + Computes when holiday is given a pandas Timestamp | 
|  | 186 | + start_date : datetime-like, default None | 
|  | 187 | + First date the holiday is observed | 
|  | 188 | + end_date : datetime-like, default None | 
|  | 189 | + Last date the holiday is observed | 
|  | 190 | + days_of_week : tuple of int or dateutil.relativedelta weekday strs, default None | 
|  | 191 | + Provide a tuple of days e.g (0,1,2,3,) for Monday Through Thursday | 
| 180 | 192 |  Monday=0,..,Sunday=6 | 
| 181 | 193 | 
 | 
| 182 | 194 |  Examples | 
| @@ -216,8 +228,19 @@ class from pandas.tseries.offsets | 
| 216 | 228 |  >>> July3rd | 
| 217 | 229 |  Holiday: July 3rd (month=7, day=3, ) | 
| 218 | 230 |  """ | 
| 219 |  | - if offset is not None and observance is not None: | 
| 220 |  | - raise NotImplementedError("Cannot use both offset and observance.") | 
|  | 231 | + if offset is not None: | 
|  | 232 | + if observance is not None: | 
|  | 233 | + raise NotImplementedError("Cannot use both offset and observance.") | 
|  | 234 | + if not ( | 
|  | 235 | + isinstance(offset, BaseOffset) | 
|  | 236 | + or ( | 
|  | 237 | + isinstance(offset, list) | 
|  | 238 | + and all(isinstance(off, BaseOffset) for off in offset) | 
|  | 239 | + ) | 
|  | 240 | + ): | 
|  | 241 | + raise ValueError( | 
|  | 242 | + "Only BaseOffsets and flat lists of them are supported for offset." | 
|  | 243 | + ) | 
| 221 | 244 | 
 | 
| 222 | 245 |  self.name = name | 
| 223 | 246 |  self.year = year | 
|  | 
0 commit comments