|
4 | 4 | datetime, |
5 | 5 | timedelta, |
6 | 6 | ) |
7 | | -from typing import ( |
8 | | - TYPE_CHECKING, |
9 | | - Callable, |
10 | | -) |
| 7 | +from typing import Callable |
11 | 8 | import warnings |
12 | 9 |
|
13 | 10 | from dateutil.relativedelta import ( |
|
21 | 18 | ) |
22 | 19 | import numpy as np |
23 | 20 |
|
| 21 | +from pandas._libs.tslibs.offsets import BaseOffset |
24 | 22 | from pandas.errors import PerformanceWarning |
25 | 23 |
|
26 | 24 | from pandas import ( |
|
37 | 35 | Easter, |
38 | 36 | ) |
39 | 37 |
|
40 | | -if TYPE_CHECKING: |
41 | | - from pandas._libs.tslibs.offsets import BaseOffset |
42 | | - |
43 | 38 |
|
44 | 39 | def next_monday(dt: datetime) -> datetime: |
45 | 40 | """ |
@@ -156,7 +151,6 @@ class Holiday: |
156 | 151 | for observance. |
157 | 152 | """ |
158 | 153 |
|
159 | | - offset: BaseOffset | list[BaseOffset] | None |
160 | 154 | start_date: Timestamp | None |
161 | 155 | end_date: Timestamp | None |
162 | 156 | days_of_week: tuple[int, ...] | None |
@@ -234,13 +228,19 @@ class from pandas.tseries.offsets, default None |
234 | 228 | >>> July3rd |
235 | 229 | Holiday: July 3rd (month=7, day=3, ) |
236 | 230 | """ |
237 | | - if offset is not None and observance is not None: |
238 | | - raise NotImplementedError("Cannot use both offset and observance.") |
239 | | - if isinstance(offset, list) and any(isinstance(off, list) for off in offset): |
240 | | - raise ValueError( |
241 | | - "Nested lists are not supported for offset. " |
242 | | - "Flatten composite offsets of `Holiday.offset`s first." |
243 | | - ) |
| 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 | + ) |
244 | 244 |
|
245 | 245 | self.name = name |
246 | 246 | self.year = year |
|
0 commit comments