|
1 | 1 | # pylint: disable=E1101,E1103,W0232
|
2 | 2 | from datetime import datetime, timedelta
|
3 |
| -import operator |
4 | 3 | import warnings
|
5 | 4 |
|
6 | 5 | import numpy as np
|
|
18 | 17 |
|
19 | 18 | from pandas import compat
|
20 | 19 | from pandas.core import common as com
|
21 |
| -from pandas.core.accessor import PandasDelegate, delegate_names |
| 20 | +from pandas.core.accessor import delegate_names |
22 | 21 | from pandas.core.algorithms import unique1d
|
23 | 22 | import pandas.core.arrays.datetimelike as dtl
|
24 | 23 | from pandas.core.arrays.period import PeriodArray, period_array
|
25 | 24 | from pandas.core.base import _shared_docs
|
26 | 25 | import pandas.core.indexes.base as ibase
|
27 | 26 | from pandas.core.indexes.base import _index_shared_docs, ensure_index
|
28 | 27 | from pandas.core.indexes.datetimelike import (
|
29 |
| - DatelikeOps, DatetimeIndexOpsMixin, wrap_arithmetic_op) |
| 28 | + DatelikeOps, DatetimeIndexOpsMixin, DatetimelikeDelegateMixin, |
| 29 | + wrap_arithmetic_op) |
30 | 30 | from pandas.core.indexes.datetimes import DatetimeIndex, Index, Int64Index
|
31 | 31 | from pandas.core.missing import isna
|
32 | 32 | from pandas.core.ops import get_op_result_name
|
@@ -54,33 +54,26 @@ def _new_PeriodIndex(cls, **d):
|
54 | 54 | return cls(values, **d)
|
55 | 55 |
|
56 | 56 |
|
57 |
| -class PeriodDelegateMixin(PandasDelegate): |
| 57 | +class PeriodDelegateMixin(DatetimelikeDelegateMixin): |
58 | 58 | """
|
59 | 59 | Delegate from PeriodIndex to PeriodArray.
|
60 | 60 | """
|
61 |
| - def _delegate_property_get(self, name, *args, **kwargs): |
62 |
| - result = getattr(self._data, name) |
63 |
| - box_ops = ( |
64 |
| - set(PeriodArray._datetimelike_ops) - set(PeriodArray._bool_ops) |
65 |
| - ) |
66 |
| - if name in box_ops: |
67 |
| - result = Index(result, name=self.name) |
68 |
| - return result |
69 |
| - |
70 |
| - def _delegate_property_set(self, name, value, *args, **kwargs): |
71 |
| - setattr(self._data, name, value) |
72 |
| - |
73 |
| - def _delegate_method(self, name, *args, **kwargs): |
74 |
| - result = operator.methodcaller(name, *args, **kwargs)(self._data) |
75 |
| - return Index(result, name=self.name) |
| 61 | + _delegate_class = PeriodArray |
| 62 | + _delegated_properties = ( |
| 63 | + PeriodArray._datetimelike_ops + ['size', 'asi8', 'shape'] |
| 64 | + ) |
| 65 | + _delegated_methods = ( |
| 66 | + set(PeriodArray._datetimelike_methods) - |
| 67 | + {'asfreq', 'to_timestamp'} | {'_addsub_int_array'} |
| 68 | + ) |
| 69 | + _raw_properties = {'is_leap_year'} |
76 | 70 |
|
77 | 71 |
|
78 | 72 | @delegate_names(PeriodArray,
|
79 |
| - PeriodArray._datetimelike_ops + ['size', 'asi8', 'shape'], |
| 73 | + PeriodDelegateMixin._delegated_properties, |
80 | 74 | typ='property')
|
81 | 75 | @delegate_names(PeriodArray,
|
82 |
| - [x for x in PeriodArray._datetimelike_methods |
83 |
| - if x not in {"asfreq", "to_timestamp"}], |
| 76 | + PeriodDelegateMixin._delegated_methods, |
84 | 77 | typ="method",
|
85 | 78 | overwrite=True)
|
86 | 79 | class PeriodIndex(DatelikeOps, DatetimeIndexOpsMixin,
|
|
0 commit comments