@@ -321,11 +321,10 @@ def _simple_new(cls, values, name=None, freq=None, tz=None, dtype=None):
321321
322322 dtarr = DatetimeArray ._simple_new (values , freq = freq , tz = tz )
323323 result = object .__new__ (cls )
324- result ._data = dtarr ._data
325- result ._freq = dtarr .freq
326- result ._tz = dtarr .tz
324+ result ._eadata = dtarr
327325 result .name = name
328326 # For groupby perf. See note in indexes/base about _index_data
327+ # TODO: make sure this is updated correctly if edited
329328 result ._index_data = result ._data
330329 result ._reset_identity ()
331330 return result
@@ -345,19 +344,6 @@ def _values(self):
345344 else :
346345 return self .values
347346
348- @property
349- def tz (self ):
350- # GH 18595
351- return self ._tz
352-
353- @tz .setter
354- def tz (self , value ):
355- # GH 3746: Prevent localizing or converting the index by setting tz
356- raise AttributeError ("Cannot directly set timezone. Use tz_localize() "
357- "or tz_convert() as appropriate" )
358-
359- tzinfo = tz
360-
361347 @property
362348 def size (self ):
363349 # TODO: Remove this when we have a DatetimeTZArray
@@ -416,15 +402,18 @@ def __setstate__(self, state):
416402 data = np .empty (nd_state [1 ], dtype = nd_state [2 ])
417403 np .ndarray .__setstate__ (data , nd_state )
418404
405+ freq = own_state [1 ]
406+ tz = timezones .tz_standardize (own_state [2 ])
407+ dtarr = DatetimeArray ._simple_new (data , freq = freq , tz = tz )
408+
419409 self .name = own_state [0 ]
420- self ._freq = own_state [1 ]
421- self ._tz = timezones .tz_standardize (own_state [2 ])
422410
423411 else : # pragma: no cover
424412 data = np .empty (state )
425413 np .ndarray .__setstate__ (data , state )
414+ dtarr = DatetimeArray (data )
426415
427- self ._data = data
416+ self ._eadata = dtarr
428417 self ._reset_identity ()
429418
430419 else :
@@ -502,7 +491,9 @@ def union(self, other):
502491 else :
503492 result = Index .union (this , other )
504493 if isinstance (result , DatetimeIndex ):
505- result ._tz = timezones .tz_standardize (this .tz )
494+ # TODO: we shouldn't be setting attributes like this;
495+ # in all the tests this equality already holds
496+ result ._eadata ._dtype = this .dtype
506497 if (result .freq is None and
507498 (this .freq is not None or other .freq is not None )):
508499 result .freq = to_offset (result .inferred_freq )
@@ -530,11 +521,12 @@ def union_many(self, others):
530521 if this ._can_fast_union (other ):
531522 this = this ._fast_union (other )
532523 else :
533- tz = this .tz
524+ dtype = this .dtype
534525 this = Index .union (this , other )
535526 if isinstance (this , DatetimeIndex ):
536- this ._tz = timezones .tz_standardize (tz )
537-
527+ # TODO: we shouldn't be setting attributes like this;
528+ # in all the tests this equality already holds
529+ this ._eadata ._dtype = dtype
538530 return this
539531
540532 def _can_fast_union (self , other ):
@@ -1129,9 +1121,20 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
11291121 # Wrapping DatetimeArray
11301122
11311123 @property
1132- def _eadata (self ):
1133- return DatetimeArray ._simple_new (self ._data ,
1134- tz = self .tz , freq = self .freq )
1124+ def _data (self ):
1125+ return self ._eadata ._data
1126+
1127+ @property
1128+ def tz (self ):
1129+ # GH#18595
1130+ return self ._eadata .tz
1131+
1132+ @tz .setter
1133+ def tz (self , value ):
1134+ # GH#3746; DatetimeArray will raise to disallow setting
1135+ self ._eadata .tz = value
1136+
1137+ tzinfo = tz
11351138
11361139 # Compat for frequency inference, see GH#23789
11371140 _is_monotonic_increasing = Index .is_monotonic_increasing
@@ -1168,18 +1171,6 @@ def offset(self, value):
11681171 warnings .warn (msg , FutureWarning , stacklevel = 2 )
11691172 self .freq = value
11701173
1171- @property
1172- def freq (self ):
1173- return self ._freq
1174-
1175- @freq .setter
1176- def freq (self , value ):
1177- if value is not None :
1178- # let DatetimeArray to validation
1179- self ._eadata .freq = value
1180-
1181- self ._freq = to_offset (value )
1182-
11831174 def __getitem__ (self , key ):
11841175 result = self ._eadata .__getitem__ (key )
11851176 if is_scalar (result ):
0 commit comments