|
75 | 75 | # DateOffset |
76 | 76 |
|
77 | 77 |
|
78 | | -class DateOffset(BaseOffset): |
| 78 | +class OffsetMeta(type): |
| 79 | + """ |
| 80 | + Metaclass that allows us to pretend that all BaseOffset subclasses |
| 81 | + inherit from DateOffset (which is needed for backward-compatibility). |
| 82 | + """ |
| 83 | + |
| 84 | + @classmethod |
| 85 | + def __instancecheck__(cls, obj) -> bool: |
| 86 | + return isinstance(obj, BaseOffset) |
| 87 | + |
| 88 | + @classmethod |
| 89 | + def __subclasscheck__(cls, obj) -> bool: |
| 90 | + return issubclass(obj, BaseOffset) |
| 91 | + |
| 92 | + |
| 93 | +class DateOffset(BaseOffset, metaclass=OffsetMeta): |
79 | 94 | """ |
80 | 95 | Standard kind of date increment used for a date range. |
81 | 96 |
|
@@ -274,25 +289,16 @@ def apply_index(self, i): |
274 | 289 | "applied vectorized" |
275 | 290 | ) |
276 | 291 |
|
277 | | - def is_anchored(self) -> bool: |
278 | | - # TODO: Does this make sense for the general case? It would help |
279 | | - # if there were a canonical docstring for what is_anchored means. |
280 | | - return self.n == 1 |
281 | | - |
282 | 292 | def is_on_offset(self, dt): |
283 | 293 | if self.normalize and not is_normalized(dt): |
284 | 294 | return False |
285 | 295 | # TODO, see #1395 |
286 | 296 | return True |
287 | 297 |
|
288 | 298 |
|
289 | | -class SingleConstructorOffset(DateOffset): |
290 | | - # All DateOffset subclasses (other than Tick) subclass SingleConstructorOffset |
291 | | - __init__ = BaseOffset.__init__ |
292 | | - _attributes = BaseOffset._attributes |
293 | | - apply_index = BaseOffset.apply_index |
294 | | - is_on_offset = BaseOffset.is_on_offset |
295 | | - _adjust_dst = True |
| 299 | +class SingleConstructorOffset(BaseOffset): |
| 300 | + _params = cache_readonly(BaseOffset._params.fget) |
| 301 | + freqstr = cache_readonly(BaseOffset.freqstr.fget) |
296 | 302 |
|
297 | 303 | @classmethod |
298 | 304 | def _from_name(cls, suffix=None): |
@@ -2305,7 +2311,7 @@ class Nano(Tick): |
2305 | 2311 | CDay = CustomBusinessDay |
2306 | 2312 |
|
2307 | 2313 | prefix_mapping = { |
2308 | | - offset._prefix: offset |
| 2314 | + offset._prefix: offset # type: ignore |
2309 | 2315 | for offset in [ |
2310 | 2316 | YearBegin, # 'AS' |
2311 | 2317 | YearEnd, # 'A' |
|
0 commit comments