@@ -654,6 +654,16 @@ def _astype(self, dtype: DtypeObj, copy: bool) -> ArrayLike:
654
654
655
655
return Categorical (values , dtype = dtype )
656
656
657
+ elif is_datetime64tz_dtype (dtype ) and is_datetime64_dtype (values .dtype ):
658
+ # if we are passed a datetime64[ns, tz]
659
+ if copy :
660
+ # this should be the only copy
661
+ values = values .copy ()
662
+ # i.e. values.tz_localize("UTC").tz_convert(dtype.tz)
663
+ # FIXME: GH#33401 this doesn't match DatetimeArray.astype, which
664
+ # would be self.array_values().tz_localize(dtype.tz)
665
+ return DatetimeArray ._simple_new (values .view ("i8" ), dtype = dtype )
666
+
657
667
if is_dtype_equal (values .dtype , dtype ):
658
668
if copy :
659
669
return values .copy ()
@@ -2237,25 +2247,6 @@ def _maybe_coerce_values(self, values):
2237
2247
assert isinstance (values , np .ndarray ), type (values )
2238
2248
return values
2239
2249
2240
- def astype (self , dtype , copy : bool = False , errors : str = "raise" ):
2241
- """
2242
- these automatically copy, so copy=True has no effect
2243
- raise on an except if raise == True
2244
- """
2245
- dtype = pandas_dtype (dtype )
2246
-
2247
- # if we are passed a datetime64[ns, tz]
2248
- if is_datetime64tz_dtype (dtype ):
2249
- values = self .values
2250
- if copy :
2251
- # this should be the only copy
2252
- values = values .copy ()
2253
- values = DatetimeArray ._simple_new (values .view ("i8" ), dtype = dtype )
2254
- return self .make_block (values )
2255
-
2256
- # delegate
2257
- return super ().astype (dtype = dtype , copy = copy , errors = errors )
2258
-
2259
2250
def _can_hold_element (self , element : Any ) -> bool :
2260
2251
tipo = maybe_infer_dtype_type (element )
2261
2252
if tipo is not None :
0 commit comments