@@ -182,7 +182,6 @@ class DatetimeIndex(DatetimeArrayMixin, DatelikeOps, TimelikeOps,
182
182
183
183
"""
184
184
_resolution = cache_readonly (DatetimeArrayMixin ._resolution .fget )
185
- _shallow_copy = Index ._shallow_copy
186
185
187
186
_typ = 'datetimeindex'
188
187
_join_precedence = 10
@@ -199,11 +198,15 @@ def _join_i8_wrapper(joinf, **kwargs):
199
198
200
199
_engine_type = libindex .DatetimeEngine
201
200
202
- tz = None
201
+ _tz = None
203
202
_freq = None
204
203
_comparables = ['name' , 'freqstr' , 'tz' ]
205
204
_attributes = ['name' , 'freq' , 'tz' ]
206
205
206
+ # dummy attribute so that datetime.__eq__(DatetimeArray) defers
207
+ # by returning NotImplemented
208
+ timetuple = None
209
+
207
210
# define my properties & methods for delegation
208
211
_bool_ops = ['is_month_start' , 'is_month_end' ,
209
212
'is_quarter_start' , 'is_quarter_end' , 'is_year_start' ,
@@ -226,6 +229,9 @@ def _join_i8_wrapper(joinf, **kwargs):
226
229
_timezone = cache_readonly (DatetimeArrayMixin ._timezone .fget )
227
230
is_normalized = cache_readonly (DatetimeArrayMixin .is_normalized .fget )
228
231
232
+ # --------------------------------------------------------------------
233
+ # Constructors
234
+
229
235
def __new__ (cls , data = None ,
230
236
freq = None , start = None , end = None , periods = None , tz = None ,
231
237
normalize = False , closed = None , ambiguous = 'raise' ,
@@ -280,7 +286,7 @@ def __new__(cls, data=None,
280
286
data = data .tz_localize (tz , ambiguous = ambiguous )
281
287
else :
282
288
# the tz's must match
283
- if str (tz ) != str ( data .tz ):
289
+ if not timezones . tz_compare (tz , data .tz ):
284
290
msg = ('data is already tz-aware {0}, unable to '
285
291
'set specified tz: {1}' )
286
292
raise TypeError (msg .format (data .tz , tz ))
@@ -327,12 +333,6 @@ def __new__(cls, data=None,
327
333
328
334
return subarr ._deepcopy_if_needed (ref_to_data , copy )
329
335
330
- def _convert_for_op (self , value ):
331
- """ Convert value to be insertable to ndarray """
332
- if self ._has_same_tz (value ):
333
- return _to_m8 (value )
334
- raise ValueError ('Passed item and index have different timezone' )
335
-
336
336
@classmethod
337
337
def _simple_new (cls , values , name = None , freq = None , tz = None ,
338
338
dtype = None , ** kwargs ):
@@ -349,6 +349,8 @@ def _simple_new(cls, values, name=None, freq=None, tz=None,
349
349
result ._reset_identity ()
350
350
return result
351
351
352
+ # --------------------------------------------------------------------
353
+
352
354
@property
353
355
def _values (self ):
354
356
# tz-naive -> ndarray
@@ -448,6 +450,12 @@ def __setstate__(self, state):
448
450
raise Exception ("invalid pickle state" )
449
451
_unpickle_compat = __setstate__
450
452
453
+ def _convert_for_op (self , value ):
454
+ """ Convert value to be insertable to ndarray """
455
+ if self ._has_same_tz (value ):
456
+ return _to_m8 (value )
457
+ raise ValueError ('Passed item and index have different timezone' )
458
+
451
459
def _maybe_update_attributes (self , attrs ):
452
460
""" Update Index attributes (e.g. freq) depending on op """
453
461
freq = attrs .get ('freq' , None )
@@ -1104,6 +1112,9 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
1104
1112
else :
1105
1113
raise
1106
1114
1115
+ # --------------------------------------------------------------------
1116
+ # Wrapping DatetimeArray
1117
+
1107
1118
year = wrap_field_accessor (DatetimeArrayMixin .year )
1108
1119
month = wrap_field_accessor (DatetimeArrayMixin .month )
1109
1120
day = wrap_field_accessor (DatetimeArrayMixin .day )
@@ -1142,6 +1153,8 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
1142
1153
month_name = wrap_array_method (DatetimeArrayMixin .month_name , True )
1143
1154
day_name = wrap_array_method (DatetimeArrayMixin .day_name , True )
1144
1155
1156
+ # --------------------------------------------------------------------
1157
+
1145
1158
@Substitution (klass = 'DatetimeIndex' )
1146
1159
@Appender (_shared_docs ['searchsorted' ])
1147
1160
def searchsorted (self , value , side = 'left' , sorter = None ):
0 commit comments