Skip to content

Commit 8f1b912

Browse files
authored
REF: use inherit_names for DTI (#31468)
1 parent 948f957 commit 8f1b912

File tree

1 file changed

+22
-42
lines changed

1 file changed

+22
-42
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020
from pandas.core.dtypes.dtypes import DatetimeTZDtype
2121
from pandas.core.dtypes.missing import is_valid_nat_for_dtype
2222

23-
from pandas.core.accessor import delegate_names
2423
from pandas.core.arrays.datetimes import (
2524
DatetimeArray,
2625
tz_to_dtype,
2726
validate_tz_from_dtype,
2827
)
2928
import pandas.core.common as com
3029
from pandas.core.indexes.base import Index, InvalidIndexError, maybe_extract_name
31-
from pandas.core.indexes.datetimelike import (
32-
DatetimelikeDelegateMixin,
33-
DatetimeTimedeltaMixin,
34-
)
30+
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
3531
from pandas.core.indexes.extension import inherit_names
3632
from pandas.core.ops import get_op_result_name
3733
import pandas.core.tools.datetimes as tools
@@ -59,32 +55,13 @@ def _new_DatetimeIndex(cls, d):
5955
return result
6056

6157

62-
class DatetimeDelegateMixin(DatetimelikeDelegateMixin):
63-
# Most attrs are dispatched via datetimelike_{ops,methods}
64-
# Some are "raw" methods, the result is not not re-boxed in an Index
65-
# We also have a few "extra" attrs, which may or may not be raw,
66-
# which we we dont' want to expose in the .dt accessor.
67-
_extra_methods = ["to_period", "to_perioddelta", "to_julian_date", "strftime"]
68-
_extra_raw_methods = [
69-
"to_pydatetime",
70-
"_local_timestamps",
71-
"_has_same_tz",
72-
"_format_native_types",
73-
"__iter__",
74-
]
75-
_extra_raw_properties = ["_box_func", "tz", "tzinfo", "dtype"]
76-
_delegated_properties = DatetimeArray._datetimelike_ops + _extra_raw_properties
77-
_delegated_methods = (
78-
DatetimeArray._datetimelike_methods + _extra_methods + _extra_raw_methods
79-
)
80-
_raw_properties = (
81-
{"date", "time", "timetz"}
82-
| set(DatetimeArray._bool_ops)
83-
| set(_extra_raw_properties)
84-
)
85-
_raw_methods = set(_extra_raw_methods)
86-
87-
58+
@inherit_names(
59+
["to_period", "to_perioddelta", "to_julian_date", "strftime"]
60+
+ DatetimeArray._field_ops
61+
+ DatetimeArray._datetimelike_methods,
62+
DatetimeArray,
63+
wrap=True,
64+
)
8865
@inherit_names(["_timezone", "is_normalized", "_resolution"], DatetimeArray, cache=True)
8966
@inherit_names(
9067
[
@@ -93,19 +70,22 @@ class DatetimeDelegateMixin(DatetimelikeDelegateMixin):
9370
"_field_ops",
9471
"_datetimelike_ops",
9572
"_datetimelike_methods",
96-
],
97-
DatetimeArray,
98-
)
99-
@delegate_names(
100-
DatetimeArray, DatetimeDelegateMixin._delegated_properties, typ="property"
101-
)
102-
@delegate_names(
73+
"_box_func",
74+
"tz",
75+
"tzinfo",
76+
"dtype",
77+
"to_pydatetime",
78+
"_local_timestamps",
79+
"_has_same_tz",
80+
"_format_native_types",
81+
"date",
82+
"time",
83+
"timetz",
84+
]
85+
+ DatetimeArray._bool_ops,
10386
DatetimeArray,
104-
DatetimeDelegateMixin._delegated_methods,
105-
typ="method",
106-
overwrite=True,
10787
)
108-
class DatetimeIndex(DatetimeTimedeltaMixin, DatetimeDelegateMixin):
88+
class DatetimeIndex(DatetimeTimedeltaMixin):
10989
"""
11090
Immutable ndarray of datetime64 data, represented internally as int64, and
11191
which can be boxed to Timestamp objects that are subclasses of datetime and

0 commit comments

Comments
 (0)