@@ -111,36 +111,17 @@ def _evaluate_compare(self, other, op):
111
111
112
112
def _ensure_localized (self , arg , ambiguous = 'raise' , nonexistent = 'raise' ,
113
113
from_utc = False ):
114
- """
115
- Ensure that we are re-localized.
116
-
117
- This is for compat as we can then call this on all datetimelike
118
- indexes generally (ignored for Period/Timedelta)
119
-
120
- Parameters
121
- ----------
122
- arg : DatetimeIndex / i8 ndarray
123
- ambiguous : str, bool, or bool-ndarray, default 'raise'
124
- nonexistent : str, default 'raise'
125
- from_utc : bool, default False
126
- If True, localize the i8 ndarray to UTC first before converting to
127
- the appropriate tz. If False, localize directly to the tz.
128
-
129
- Returns
130
- -------
131
- localized DTI
132
- """
133
-
134
- # reconvert to local tz
135
- if getattr (self , 'tz' , None ) is not None :
136
- if not isinstance (arg , ABCIndexClass ):
137
- arg = self ._simple_new (arg )
138
- if from_utc :
139
- arg = arg .tz_localize ('UTC' ).tz_convert (self .tz )
140
- else :
141
- arg = arg .tz_localize (
142
- self .tz , ambiguous = ambiguous , nonexistent = nonexistent
143
- )
114
+ # See DatetimeLikeArrayMixin._ensure_localized.__doc__
115
+
116
+ if getattr (self , 'tz' , None ):
117
+ # ensure_localized is only relevant for tz-aware DTI
118
+ from pandas .core .arrays import DatetimeArrayMixin as DatetimeArray
119
+ dtarr = DatetimeArray (self )
120
+ result = dtarr ._ensure_localized (arg ,
121
+ ambiguous = ambiguous ,
122
+ nonexistent = nonexistent ,
123
+ from_utc = from_utc )
124
+ return type (self )(result , name = self .name )
144
125
return arg
145
126
146
127
def _box_values_as_index (self ):
0 commit comments