2
2
Base and utility classes for tseries type pandas objects.
3
3
"""
4
4
from datetime import datetime
5
- from typing import TYPE_CHECKING , Any , List , Optional , Tuple , TypeVar , Union , cast
5
+ from typing import TYPE_CHECKING , Any , List , Optional , Tuple , Type , TypeVar , Union , cast
6
6
7
7
import numpy as np
8
8
@@ -88,6 +88,7 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex):
88
88
89
89
_can_hold_strings = False
90
90
_data : Union [DatetimeArray , TimedeltaArray , PeriodArray ]
91
+ _data_cls : Union [Type [DatetimeArray ], Type [TimedeltaArray ], Type [PeriodArray ]]
91
92
freq : Optional [BaseOffset ]
92
93
freqstr : Optional [str ]
93
94
_resolution_obj : Resolution
@@ -100,6 +101,25 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex):
100
101
)
101
102
_hasnans = hasnans # for index / array -agnostic code
102
103
104
+ @classmethod
105
+ def _simple_new (
106
+ cls ,
107
+ values : Union [DatetimeArray , TimedeltaArray , PeriodArray ],
108
+ name : Label = None ,
109
+ ):
110
+ assert isinstance (values , cls ._data_cls ), type (values )
111
+
112
+ result = object .__new__ (cls )
113
+ result ._data = values
114
+ result ._name = name
115
+ result ._cache = {}
116
+
117
+ # For groupby perf. See note in indexes/base about _index_data
118
+ result ._index_data = values ._data
119
+
120
+ result ._reset_identity ()
121
+ return result
122
+
103
123
@property
104
124
def _is_all_dates (self ) -> bool :
105
125
return True
0 commit comments